SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
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

Contenu connexe

En vedette

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
 

En vedette (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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 

Dernier (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

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