Functional programming is on the rise, but it's not all just academic thought exercises, it can be a pragmatic solution to real world problems. I cover what I think pragmatism looks like and why functional languages like Scala can be pragmatic
website content ✤ Limited beta released early 2009 ✤ Started implementation of final version late 2009 ✤ Live May 2010: http://content.guardianapis.com Saturday, 3 November 12
Immutability and Category Theory allow proof of program ✤ “I have only proved it correct, not tried it” ✤ The “inventors” of functional Saturday, 3 November 12
Immutability and Category Theory allow proof of program ✤ “I have only proved it correct, not tried it” ✤ The “inventors” of functional ✤ Fierce protectors of it Saturday, 3 November 12
so it can’t be misused ✤ Inner details of my library don’t leak out because: ✤ Monads keep operations inside themselves ✤ Applicative Functors mean I can chain my operations nicely Saturday, 3 November 12
so it can’t be misused ✤ Inner details of my library don’t leak out because: ✤ Monads keep operations inside themselves ✤ Applicative Functors mean I can chain my operations nicely ✤ Currying means I can return implementation easily. Saturday, 3 November 12
✤ Don’t use one Golden framework ✤ Select a framework on ease of use and ease of hacking ✤ Know when to move away ✤ Django, Rails, Lift etc Saturday, 3 November 12
use it ✤ Build a toolkit of libraries that just work for you ✤ Simplicity over Correctness ✤ e.g. scalaj-http vs dispatch - or sometimes you don’t care about async Saturday, 3 November 12
use it ✤ Build a toolkit of libraries that just work for you ✤ Simplicity over Correctness ✤ e.g. scalaj-http vs dispatch - or sometimes you don’t care about async ✤ (and sometimes you do!) Saturday, 3 November 12
to ensure/prove I have fewer bugs ✤ Immutable monadic data structures == highly concurrent ✤ Category theory means... ✤ I have no idea what category theory means, but it’s awesome right? Saturday, 3 November 12
interviews ✤ “I want to learn Scala, I hear you are the best” ✤ Most common reason for joining ✤ Works as a great recruitment filter Saturday, 3 November 12
interviews ✤ “I want to learn Scala, I hear you are the best” ✤ Most common reason for joining ✤ Works as a great recruitment filter ✤ Just say No to J2EE Saturday, 3 November 12
✤ Null Pointer Exception is the bane of every java programmers life ✤ Don’t allow null values in your functional code, ever! ✤ Where you may not have a value, use an option Saturday, 3 November 12
✤ Null Pointer Exception is the bane of every java programmers life ✤ Don’t allow null values in your functional code, ever! ✤ Where you may not have a value, use an option ✤ Avoid “Optionitus” Saturday, 3 November 12
member.getAs[DBObject]("location") match { case Some(location) => { location.getAs[DBObject]("geolocation") match { case Some(geolocation : DBObject) => { geolocation.getAs[Double]("latitude") match { case Some(latitude : Double) => { geolocation.getAs[Double]("longitude") match { case Some(longitude : Double) => { SpatialFilterCriterion(latitude, longitude, 25, "miles") } case _ => } } case _ => } } case _ => } } case _ => } Saturday, 3 November 12
member.getAs[DBObject]("location") match { case Some(location) => { location.getAs[DBObject]("geolocation") match { case Some(geolocation : DBObject) => { geolocation.getAs[Double]("latitude") match { case Some(latitude : Double) => { geolocation.getAs[Double]("longitude") match { case Some(longitude : Double) => { SpatialFilterCriterion(latitude, longitude, 25, "miles") } case _ => } } case _ => } } case _ => } } case _ => } Phil Wills says “flatMap that shit” MBS says “for-comprehensions are awesome” Saturday, 3 November 12
should know about Linked Lists, Red-Black trees etc, ✤ But I don’t want to write one, I just want to get stuff done ✤ Academics have done this work for me. Saturday, 3 November 12
should know about Linked Lists, Red-Black trees etc, ✤ But I don’t want to write one, I just want to get stuff done ✤ Academics have done this work for me. ✤ I’m really not going to do a better job Saturday, 3 November 12
actual functional ✤ Sequences of data structures ✤ Map, Filter, Accumulate ✤ Use where it makes sense to think of the problem as a pipeline of transformations Saturday, 3 November 12
faster in functional ✤ The day it’s easier in functional ✤ The day it’s the pragmatic solution ✤ They will never care for category theory Saturday, 3 November 12
faster in functional ✤ The day it’s easier in functional ✤ The day it’s the pragmatic solution ✤ They will never care for category theory ✤ probably Saturday, 3 November 12