SlideShare a Scribd company logo
1 of 37
Download to read offline
REAL
                                                 W⊛RLD
                                                 SCALAZ
                          http://speakerdeck.com/u/jrwest/p/real-world-scalaz
changed talk title (“practical scalaz” by Chris Marshall http://skillsmatter.com/podcast/scala/practical-scalaz-2518)
“If you are thinking of using
        Scalaz, stop now while you
        still have your sanity"
* context: java devs learning scala
* source: http://zeroturnaround.com/blog/scala-sink-or-swim-part-1/#scalaz
“How does this help
        you ship features or
        improve your product?”
* context: commenting on the use of lenses
* source: https://twitter.com/#!/coda/status/167794305107361796)
“It will not immediately
        help you write better
        programs that are easy to
        understand”
* hear/read this often
* source: http://zeroturnaround.com/blog/scala-sink-or-swim-part-1/#scalaz
“There are two types of
          [libraries]: the ones people hate
                and the ones nobody uses”
                                - unknown
* applies to scala too
* know correct attribution? contact me
HOW
                                               &
                                              WHY?
* those quotes pretty much boil down to these two questions:
* how: apply tools given by scalaz to real world problems? to handle human scale?
* why would we choose this solution over other ones?
@_jrwest
                                                           github.com/jrwest
                                                           blog.loopedstrange.com




* a little context before we talk about the “how & why?”
I
                                             WORK @



* small team, < 15 engineers
* many have java bg, but not all, most w/ little to no scala experience
* most have oop bg, varying knowledge of FP topics
WE USE SCALA
                         { a lot }
* 15+ public facing services supported by many other internal modules/libs
* most built on netty, also I/O bound
* originally java, now > 70% scala
libraryDependencies +=

      “org.scalaz” %% “scalaz-core” % “6.0.3”



* almost all our services depend on scalaz
* usage levels and parts of scalaz used vary among services
* blocked on upgrading to 6.0.4 b/c of binary compatibility issues
SOME
EXAMPLES
JSON Mapping
   def Fi
          leMani
     def re          festJS
              ad(jso        ONR =
     ma                n: JVa      new JS
         nifest               lue) =       ONR[ Ap
                    NoId.a                         p I D= > F
         field(            pplyJS                             ileMan
                   jsonMa         O N(                               ifest]
        f i e l d(        nifest                                            {
      )(json       change        K e y) ,
               )          LogEnt
  }                              ryCach
                                          edJson
}                                                K e y)




* lift-json-scalaz (https://github.com/lift/framework/tree/master/core/json-scalaz)
* validationnel applicative, error accumulation = better user-facing errors & debugging
* composition
S @-@ A / State[S,A]
           for
               {
          mbE
         _    xis
            <-    ts
        _       man   <-
           <-       ife    man
     } y       cha      stF    ife
         iel       nge       ile   stF
             d m       Log       s -   ile
                 bEx        Ent      = p   s m
                     ist        ryF      ath   emb
                         s          ile            er
                                        s -           pat
                                            =?            h
                                                (pa
                                                    th,
                                                        mbE
                                                            xi          sts
                                                                              >|
                                                                                   fal
                                                                                         se
                                                                                              | t
                                                                                                  rue
                                                                                                      )
* easy manipulation of highly nested case classes (ex: file manifests)
* better implementation hiding
* rich libraries (e.g. MapLens, SetLens, & provided state actions)
sideEffect.pure[IO]
                                                           ble ,X]
                                                 [ Thr owa       = {
                                       io  n NEL         in g])        _))
                              al i dat          st [ Str      mai n] (
                       X ]=V              :  Li           mDo
             y pe  V[           s (ke ys          [Cu sto
           t          tch  K ey
                                       t .fe  tch                       ain ]])
            def   fe           buc  ke                          tom Dom
                          ap (                              Cus
                ke y s.m                           pti on[
                         qu e nce         ce[  V,O
                   .se          seq  uen
                           (_.
                   .  map
               
              }


* can’t guarantee purity, can delineate impurity
* examples: storing data in riak, uploading files to s3 and phonegap build svc
* composition of IO makes side-effecting code much more reusable
Kle




                                                                        ]
       i   sli




                                                                          ]
                         OptionW[A] Tree[A]




                                                                       F[_
                 [M
                   [_]




                                                                    le[
                       ,A,   Pure[P[_]
                          B]           ]




                                                                  ab
                                                                       MAB[M[
                                                                                _],A,B]




                                                                 ld
     Bind[Z[                                            [A]
             _                 ]]                    ro




                                                              Fo
                                       Ze                                          t[ A]
             Tra                                                           ty   Lis
                 ver             Identity                         ] NonEmp
                                                           p [   A
               e [T  s                                    u
      Fun          [_]]        r                        o
         ctor              mig          Appl
              [F[_]     Se                   y[A[_
                    ]      MA[ M[_ ],A]            ]]
* we make use of a lot more as well
* data structures like Validation and NonEmptyList
* most type classes and “enrichments”
ITS NOT ALL OR NOTHING
* shades of grey, not black and white
* scalaz is really many libraries, use the parts you want
* we started using “encrichments” and some data structures, grew from there
--
original image: http://www.chicagonow.com/chicago-tough/files/2012/03/chipsallin.jpg
MAKE BORDERS
* don’t abuse scala’s flexibility & power
* toss pure/impure code into a salad bowl & mixing is a bad idea
* define borders where pure code meets impure code
--
original image: http://media.nowpublic.net/images//59/4/59455eabd625a15e2afb583dcfbb27ce.jpg
Public Interface

                       Implementation
                     Dependency Calls
* your code can be pure
* public interface is the border, it runs IO, throws exceptions, etc
* existing libraries probably aren’t pure -- many are java after all
Outside World

                        Business Logic
* communicate with clients via HTTP
                                   Data Access
* the most important part -- your code -- make pure*
* perform side-effects like talk to database, read/write files, etc
Impure

                                               Pure
                                          Impure
* “the sandwich” - common pattern in our code
--
original image: http://fastfood.ocregister.com/files/2010/05/ice-cream-sandwich1.jpg
:)
* code has become much more DRY/modular and as a result more unit testable
* concurrent code becomes “simpler” to reason about when pure
* FP makes reasoning about bugs simpler, narrow down cause faster
:(
* scala hardsips: bin. compatability problems, tooling deficiencies, type inference limits
* import scalaz._; import Scalaz._ adds a lot of clutter in the current scope
* lack of docs/related content (in Scala!)
scalaz7
* not currently used in our production systems but one or two of my side projects
* much better for teaching (explicit type class instance usage -- w/o syntax ext.)
* addresses some of the issues we have like importing “the scalaz world”
“SCALE”?
“Human Scale”
* the complexity comments may be FUD, but that does not mean there is not stuff to learn here
* how do we help new employees learn scala & scalaz?
HIRE PEOPLE WHO
                      WANT TO LEARN
* hiring from all backgrounds instead of hiring a “scala or java developer” is much easier
* those people need to be open to exploring and learning new tech/methods
Shared Resources
* easy win, shares effort in finding good resources
* dropbox full of downloaded papers and books purchased by the company
* internal talks available on github
* code review/pull requests
                            LEARN TOGETHER
* face to face discussion on a whiteboard
* team talks on fridays, any one can attend, anyone can talk, neither mandatory
ON YOUR OWN
* RTFC -- in the end it all just code
* apply what you know, this is what really makes you learn it
* internal talks mostly make you aware of it, give you starting point, application is key
ITS NOT ALL OR NOTHING
* focus on understanding a part of the library
* break that part down, use it in the repl in a few cases (w/ a few types, examples, etc)
* as you learn more about each part and then more parts the bigger picture emerges
--
original image: http://www.chicagonow.com/chicago-tough/files/2012/03/chipsallin.jpg
Learn You a
                                                                          ??
* not necessary
* understanding syntax, basics can be useful while learning concepts until scala docs fill out
--
haskell logo: http://www.haskell.org/wikistatic/haskellwiki_logo.png
ASK #scalaz
 FOR HELP
BREAK
                                         RULES
* you may hear things you cannot do, “validation is not a monad”
* ignore and explore yourself -- these are the real learning opportunites
* understand how to implement validation monad and why no error accum. happens
PAYING
                                     UPFRONT
* of course this have some upfront cost
* so does writing tests and similarly a good balance pays off
L3
                             L2
                             L1
                             A3
                                                                           Level
                             A2
                             A1
                                                                            Up
* scalaz covers most advanced features in scala language
* great guide for library and code design (to an extent). Scalaz guys have done serious amount of research in this regard
Thanks!
talk recap slide
SOME RESOURCES
• Atlassian’s Typeclassopedia - http://typeclassopedia.bitbucket.org
• Apocalisp Blog - http://apocalisp.wordpress.com/
• “Functional Programming in Scala” MEAP - http://manning.com/bjarnason/
• Eric Torreborre’s Blog - http://etorreborre.blogspot.com/
• StackMob Engineering Blog - http://www.stackmob.com/category/engineering/
• Learn You a Scalaz (my WIP, about to undergo major rework) -
https://github.com/jrwest/learn-you-a-scalaz

• Chris Marshall’s “Practical Scalaz” Talk - http://skillsmatter.com/podcast/scala/
practical-scalaz-2518

More Related Content

Viewers also liked

building blocks of a scalable webcrawler
building blocks of a scalable webcrawlerbuilding blocks of a scalable webcrawler
building blocks of a scalable webcrawlerMarc Seeger
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programmingMichael Neale
 
Building Micro-Services with Scala
Building Micro-Services with ScalaBuilding Micro-Services with Scala
Building Micro-Services with ScalaYardena Meymann
 
Web Crawling and Data Gathering with Apache Nutch
Web Crawling and Data Gathering with Apache NutchWeb Crawling and Data Gathering with Apache Nutch
Web Crawling and Data Gathering with Apache NutchSteve Watt
 
Shift: Real World Migration from MongoDB to Cassandra
Shift: Real World Migration from MongoDB to CassandraShift: Real World Migration from MongoDB to Cassandra
Shift: Real World Migration from MongoDB to CassandraDataStax
 
Building microservices with Scala, functional domain models and Spring Boot
Building microservices with Scala, functional domain models and Spring BootBuilding microservices with Scala, functional domain models and Spring Boot
Building microservices with Scala, functional domain models and Spring BootChris Richardson
 
Resilient Applications with Akka Persistence - Scaladays 2014
Resilient Applications with Akka Persistence - Scaladays 2014Resilient Applications with Akka Persistence - Scaladays 2014
Resilient Applications with Akka Persistence - Scaladays 2014Björn Antonsson
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyBozhidar Bozhanov
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesKonrad Malawski
 
MongoDB as Message Queue
MongoDB as Message QueueMongoDB as Message Queue
MongoDB as Message QueueMongoDB
 

Viewers also liked (11)

building blocks of a scalable webcrawler
building blocks of a scalable webcrawlerbuilding blocks of a scalable webcrawler
building blocks of a scalable webcrawler
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programming
 
Building Micro-Services with Scala
Building Micro-Services with ScalaBuilding Micro-Services with Scala
Building Micro-Services with Scala
 
Web Crawling and Data Gathering with Apache Nutch
Web Crawling and Data Gathering with Apache NutchWeb Crawling and Data Gathering with Apache Nutch
Web Crawling and Data Gathering with Apache Nutch
 
Shift: Real World Migration from MongoDB to Cassandra
Shift: Real World Migration from MongoDB to CassandraShift: Real World Migration from MongoDB to Cassandra
Shift: Real World Migration from MongoDB to Cassandra
 
Building microservices with Scala, functional domain models and Spring Boot
Building microservices with Scala, functional domain models and Spring BootBuilding microservices with Scala, functional domain models and Spring Boot
Building microservices with Scala, functional domain models and Spring Boot
 
Resilient Applications with Akka Persistence - Scaladays 2014
Resilient Applications with Akka Persistence - Scaladays 2014Resilient Applications with Akka Persistence - Scaladays 2014
Resilient Applications with Akka Persistence - Scaladays 2014
 
Scala - the good, the bad and the very ugly
Scala - the good, the bad and the very uglyScala - the good, the bad and the very ugly
Scala - the good, the bad and the very ugly
 
Akka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutesAkka persistence == event sourcing in 30 minutes
Akka persistence == event sourcing in 30 minutes
 
Event-sourced architectures with Akka
Event-sourced architectures with AkkaEvent-sourced architectures with Akka
Event-sourced architectures with Akka
 
MongoDB as Message Queue
MongoDB as Message QueueMongoDB as Message Queue
MongoDB as Message Queue
 

Similar to Real World Scalaz

Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Derek Chen-Becker
 
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)Eugene Yokota
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerDavid Muñoz Díaz
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersMiles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersMiles Sabin
 
Jugar Introduccion a Scala
Jugar Introduccion a ScalaJugar Introduccion a Scala
Jugar Introduccion a ScalaSocialmetrix
 
The Very ^ 2 Basics of R
The Very ^ 2 Basics of RThe Very ^ 2 Basics of R
The Very ^ 2 Basics of RWinston Chen
 
RESTful Services
RESTful ServicesRESTful Services
RESTful ServicesKurt Cagle
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019Leonardo Borges
 
JSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptJSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptChristopher Chedeau
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesCHOOSE
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersMiles Sabin
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersSkills Matter
 
Scala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosScala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosGenevaJUG
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciencesalexstorer
 

Similar to Real World Scalaz (20)

Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
 
Java
JavaJava
Java
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmer
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Jugar Introduccion a Scala
Jugar Introduccion a ScalaJugar Introduccion a Scala
Jugar Introduccion a Scala
 
The Very ^ 2 Basics of R
The Very ^ 2 Basics of RThe Very ^ 2 Basics of R
The Very ^ 2 Basics of R
 
RESTful Services
RESTful ServicesRESTful Services
RESTful Services
 
From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019From Java to Parellel Clojure - Clojure South 2019
From Java to Parellel Clojure - Clojure South 2019
 
JSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into JavascriptJSPP: Morphing C++ into Javascript
JSPP: Morphing C++ into Javascript
 
J
JJ
J
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
 
Scala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosScala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian Dragos
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
 

More from Skills Matter Talks

(Oleg zhurakousky)spring integration-scala-intro
(Oleg zhurakousky)spring integration-scala-intro(Oleg zhurakousky)spring integration-scala-intro
(Oleg zhurakousky)spring integration-scala-introSkills Matter Talks
 
SCALA DAYS 2012: Ben Parker on Interactivity - Anti-XML in Anger
SCALA DAYS 2012: Ben Parker on Interactivity - Anti-XML in AngerSCALA DAYS 2012: Ben Parker on Interactivity - Anti-XML in Anger
SCALA DAYS 2012: Ben Parker on Interactivity - Anti-XML in AngerSkills Matter Talks
 
Project kepler compile time metaprogramming for scala
Project kepler compile time metaprogramming for scalaProject kepler compile time metaprogramming for scala
Project kepler compile time metaprogramming for scalaSkills Matter Talks
 
CukeUp! 2012: Michael Nacos on Just enough infrastructure for product develop...
CukeUp! 2012: Michael Nacos on Just enough infrastructure for product develop...CukeUp! 2012: Michael Nacos on Just enough infrastructure for product develop...
CukeUp! 2012: Michael Nacos on Just enough infrastructure for product develop...Skills Matter Talks
 
Martin sustrik future_of_messaging
Martin sustrik future_of_messagingMartin sustrik future_of_messaging
Martin sustrik future_of_messagingSkills Matter Talks
 

More from Skills Matter Talks (14)

Couch db skillsmatter-prognosql
Couch db skillsmatter-prognosqlCouch db skillsmatter-prognosql
Couch db skillsmatter-prognosql
 
Zaharia spark-scala-days-2012
Zaharia spark-scala-days-2012Zaharia spark-scala-days-2012
Zaharia spark-scala-days-2012
 
Cnc scala-presentation
Cnc scala-presentationCnc scala-presentation
Cnc scala-presentation
 
Arvindsujeeth scaladays12
Arvindsujeeth scaladays12Arvindsujeeth scaladays12
Arvindsujeeth scaladays12
 
(Oleg zhurakousky)spring integration-scala-intro
(Oleg zhurakousky)spring integration-scala-intro(Oleg zhurakousky)spring integration-scala-intro
(Oleg zhurakousky)spring integration-scala-intro
 
SCALA DAYS 2012: Ben Parker on Interactivity - Anti-XML in Anger
SCALA DAYS 2012: Ben Parker on Interactivity - Anti-XML in AngerSCALA DAYS 2012: Ben Parker on Interactivity - Anti-XML in Anger
SCALA DAYS 2012: Ben Parker on Interactivity - Anti-XML in Anger
 
Scala days mizushima
Scala days mizushimaScala days mizushima
Scala days mizushima
 
Project kepler compile time metaprogramming for scala
Project kepler compile time metaprogramming for scalaProject kepler compile time metaprogramming for scala
Project kepler compile time metaprogramming for scala
 
Test driven infrastructure
Test driven infrastructureTest driven infrastructure
Test driven infrastructure
 
CukeUp! 2012: Michael Nacos on Just enough infrastructure for product develop...
CukeUp! 2012: Michael Nacos on Just enough infrastructure for product develop...CukeUp! 2012: Michael Nacos on Just enough infrastructure for product develop...
CukeUp! 2012: Michael Nacos on Just enough infrastructure for product develop...
 
Prediction suretogowrong
Prediction suretogowrongPrediction suretogowrong
Prediction suretogowrong
 
Tmt predictions 2011
Tmt predictions 2011Tmt predictions 2011
Tmt predictions 2011
 
Martin sustrik future_of_messaging
Martin sustrik future_of_messagingMartin sustrik future_of_messaging
Martin sustrik future_of_messaging
 
Marek pubsubhuddle realtime_web
Marek pubsubhuddle realtime_webMarek pubsubhuddle realtime_web
Marek pubsubhuddle realtime_web
 

Recently uploaded

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 

Real World Scalaz

  • 1. REAL W⊛RLD SCALAZ http://speakerdeck.com/u/jrwest/p/real-world-scalaz changed talk title (“practical scalaz” by Chris Marshall http://skillsmatter.com/podcast/scala/practical-scalaz-2518)
  • 2. “If you are thinking of using Scalaz, stop now while you still have your sanity" * context: java devs learning scala * source: http://zeroturnaround.com/blog/scala-sink-or-swim-part-1/#scalaz
  • 3. “How does this help you ship features or improve your product?” * context: commenting on the use of lenses * source: https://twitter.com/#!/coda/status/167794305107361796)
  • 4. “It will not immediately help you write better programs that are easy to understand” * hear/read this often * source: http://zeroturnaround.com/blog/scala-sink-or-swim-part-1/#scalaz
  • 5. “There are two types of [libraries]: the ones people hate and the ones nobody uses” - unknown * applies to scala too * know correct attribution? contact me
  • 6. HOW & WHY? * those quotes pretty much boil down to these two questions: * how: apply tools given by scalaz to real world problems? to handle human scale? * why would we choose this solution over other ones?
  • 7. @_jrwest github.com/jrwest blog.loopedstrange.com * a little context before we talk about the “how & why?”
  • 8. I WORK @ * small team, < 15 engineers * many have java bg, but not all, most w/ little to no scala experience * most have oop bg, varying knowledge of FP topics
  • 9. WE USE SCALA { a lot } * 15+ public facing services supported by many other internal modules/libs * most built on netty, also I/O bound * originally java, now > 70% scala
  • 10. libraryDependencies += “org.scalaz” %% “scalaz-core” % “6.0.3” * almost all our services depend on scalaz * usage levels and parts of scalaz used vary among services * blocked on upgrading to 6.0.4 b/c of binary compatibility issues
  • 12. JSON Mapping def Fi leMani def re festJS ad(jso ONR =    ma n: JVa new JS nifest lue) = ONR[ Ap NoId.a p I D= > F field( pplyJS ileMan jsonMa O N( ifest] f i e l d( nifest { )(json change K e y) , ) LogEnt   } ryCach edJson } K e y) * lift-json-scalaz (https://github.com/lift/framework/tree/master/core/json-scalaz) * validationnel applicative, error accumulation = better user-facing errors & debugging * composition
  • 13. S @-@ A / State[S,A] for { mbE   _ xis <- ts   _ man <- <- ife man } y cha stF ife iel nge ile stF d m Log s - ile bEx Ent = p s m ist ryF ath emb s ile er s - pat =? h (pa th, mbE xi sts >| fal se | t rue ) * easy manipulation of highly nested case classes (ex: file manifests) * better implementation hiding * rich libraries (e.g. MapLens, SetLens, & provided state actions)
  • 14. sideEffect.pure[IO] ble ,X] [ Thr owa = { io n NEL in g]) _)) al i dat st [ Str mai n] ( X ]=V : Li mDo y pe V[ s (ke ys [Cu sto  t tch K ey t .fe tch ain ]]) def fe buc ke tom Dom ap ( Cus ke y s.m pti on[   qu e nce ce[ V,O   .se seq uen    (_.   . map      } * can’t guarantee purity, can delineate impurity * examples: storing data in riak, uploading files to s3 and phonegap build svc * composition of IO makes side-effecting code much more reusable
  • 15. Kle ] i sli ] OptionW[A] Tree[A] F[_ [M [_] le[ ,A, Pure[P[_] B] ] ab MAB[M[ _],A,B] ld Bind[Z[ [A] _ ]] ro Fo Ze t[ A] Tra ty Lis ver Identity ] NonEmp p [ A e [T s u Fun [_]] r o ctor mig Appl [F[_] Se y[A[_ ] MA[ M[_ ],A] ]] * we make use of a lot more as well * data structures like Validation and NonEmptyList * most type classes and “enrichments”
  • 16. ITS NOT ALL OR NOTHING * shades of grey, not black and white * scalaz is really many libraries, use the parts you want * we started using “encrichments” and some data structures, grew from there -- original image: http://www.chicagonow.com/chicago-tough/files/2012/03/chipsallin.jpg
  • 17. MAKE BORDERS * don’t abuse scala’s flexibility & power * toss pure/impure code into a salad bowl & mixing is a bad idea * define borders where pure code meets impure code -- original image: http://media.nowpublic.net/images//59/4/59455eabd625a15e2afb583dcfbb27ce.jpg
  • 18. Public Interface Implementation Dependency Calls * your code can be pure * public interface is the border, it runs IO, throws exceptions, etc * existing libraries probably aren’t pure -- many are java after all
  • 19. Outside World Business Logic * communicate with clients via HTTP Data Access * the most important part -- your code -- make pure* * perform side-effects like talk to database, read/write files, etc
  • 20. Impure Pure Impure * “the sandwich” - common pattern in our code -- original image: http://fastfood.ocregister.com/files/2010/05/ice-cream-sandwich1.jpg
  • 21. :) * code has become much more DRY/modular and as a result more unit testable * concurrent code becomes “simpler” to reason about when pure * FP makes reasoning about bugs simpler, narrow down cause faster
  • 22. :( * scala hardsips: bin. compatability problems, tooling deficiencies, type inference limits * import scalaz._; import Scalaz._ adds a lot of clutter in the current scope * lack of docs/related content (in Scala!)
  • 23. scalaz7 * not currently used in our production systems but one or two of my side projects * much better for teaching (explicit type class instance usage -- w/o syntax ext.) * addresses some of the issues we have like importing “the scalaz world”
  • 25. “Human Scale” * the complexity comments may be FUD, but that does not mean there is not stuff to learn here * how do we help new employees learn scala & scalaz?
  • 26. HIRE PEOPLE WHO WANT TO LEARN * hiring from all backgrounds instead of hiring a “scala or java developer” is much easier * those people need to be open to exploring and learning new tech/methods
  • 27. Shared Resources * easy win, shares effort in finding good resources * dropbox full of downloaded papers and books purchased by the company * internal talks available on github
  • 28. * code review/pull requests LEARN TOGETHER * face to face discussion on a whiteboard * team talks on fridays, any one can attend, anyone can talk, neither mandatory
  • 29. ON YOUR OWN * RTFC -- in the end it all just code * apply what you know, this is what really makes you learn it * internal talks mostly make you aware of it, give you starting point, application is key
  • 30. ITS NOT ALL OR NOTHING * focus on understanding a part of the library * break that part down, use it in the repl in a few cases (w/ a few types, examples, etc) * as you learn more about each part and then more parts the bigger picture emerges -- original image: http://www.chicagonow.com/chicago-tough/files/2012/03/chipsallin.jpg
  • 31. Learn You a ?? * not necessary * understanding syntax, basics can be useful while learning concepts until scala docs fill out -- haskell logo: http://www.haskell.org/wikistatic/haskellwiki_logo.png
  • 33. BREAK RULES * you may hear things you cannot do, “validation is not a monad” * ignore and explore yourself -- these are the real learning opportunites * understand how to implement validation monad and why no error accum. happens
  • 34. PAYING UPFRONT * of course this have some upfront cost * so does writing tests and similarly a good balance pays off
  • 35. L3 L2 L1 A3 Level A2 A1 Up * scalaz covers most advanced features in scala language * great guide for library and code design (to an extent). Scalaz guys have done serious amount of research in this regard
  • 37. SOME RESOURCES • Atlassian’s Typeclassopedia - http://typeclassopedia.bitbucket.org • Apocalisp Blog - http://apocalisp.wordpress.com/ • “Functional Programming in Scala” MEAP - http://manning.com/bjarnason/ • Eric Torreborre’s Blog - http://etorreborre.blogspot.com/ • StackMob Engineering Blog - http://www.stackmob.com/category/engineering/ • Learn You a Scalaz (my WIP, about to undergo major rework) - https://github.com/jrwest/learn-you-a-scalaz • Chris Marshall’s “Practical Scalaz” Talk - http://skillsmatter.com/podcast/scala/ practical-scalaz-2518