Scala @ TomTom
-
Upload
eric-bowman -
Category
Technology
-
view
3.264 -
download
1
Transcript of Scala @ TomTom
PowerPoint Presentation
Scala @ TomTomEric [email protected] May 2010
Whats He Building In There?Not just PNDsTraffic ServicesLocation ServicesAddress & Local SearchTons of Data Tons of AnalysisDeep Commitment to Server-Side Java2
3
4
5Company Confidential
21,345 pages40 reams of paper5 laptops8 keyboards1 back operation30,000 strands of hair
6
7
Tutorial on Good Lisp Programming Style8Most algorithms can be characterized as: Searching (some find find-if mismatch) Sorting (sort merge remove-duplicates) Filtering (remove remove-if mapcan) Mapping (map mapcar mapc) Combining (reduce mapcan) Counting (count count-if)
These functions abstract common control patterns. Code that uses them is: Concise Self-documenting Easy to understand Often reusable Usually efficient
From Peter Norvigs Tutorial on Good Lisp Programming Style , 1993 (http://www.norvig.com/luv-slides.ps)
But...Lisp is good for:Exploratory programmingRapid prototypingMinimizing time-to-marketSingle-programmer (or single-digit team) projectsSource-to-source or data-to-data transformation (ibid.)9
I LikeStatic typesRefactoring ToolsLazy SundaysPaying Some Kid To Cut The GrassSpreadsheetsNot Flying The Plane
10
What is this Scala thing?11
Scala Is...An escaped research language from EPFL targeting JVM and CLRObject-oriented and functionalStatically typedLisp, ML, Haskell, Erlang, etc.DSL-friendly
12
Bi-Scalar Disorder
13
Functional Programming?Functions as first class objectsImmutabilityClosuresBinding free variables to enclosing lexical scope Higher-order Functionsfunctions as input and/or outputA different set of idioms...14
Keep Backfor (int i = 1; i recurse(term :: prefix, tail)) }
recurse(Nil,query.split(\\s).toList.reverse).map(_.mkString( ))}
30
31
Yeah yeah yeah butPerl Whitespace Law Each line of perl should be surrounded by whitespace equivalent to what it would take to achieve the same functionality in a normal programming language. -- Don HopkinsIf it compiles, it nearly works. Really.Visual Plane-Oriented ProgrammingI IdiomsBut in Java, each little part is so very simple...
32
33
Discovering Fire34
Weak developers will move heaven and earth to do the wrong thing. You cant limit the damage they do by locking up the sharp tools. Theyll just swing the blunt tools harder. Glenn Vandenburg35
@TomTomTestingMiddleware Smart Content SwitchWe needed it quickly...B2B/B2G Traffic Query EngineClustering AlgorithmDSL Templating EngineContent CleanupNext-Generation Geocoder
36
How To Sneak It InStart with TestingScalaCheck IS AWESOME.Specs, ScalaTest testing DSLsStart with something low riskOk, well, we didnt do thatPrepare for steep learning curve...followed by a productivity hockey stick37
Another Example8000 lines of broken Java 400 lines of broken Scala
hyp.take(1).flatMap(_.dropDistricts) match { case Nil => hyp case head => { hyp.tail.foldLeft(head) { case (run: List[Hypothesis], h: Hypothesis) => { run.flatMap(_.merge(h)) match { case Nil => run case newRun => newRun.removeDuplicates } } } }}*Includes suggested improvements by Martin Odersky, I hope38
TestingFunctional architect wrote a bunch of test cases, like:
Requirement R.17:D1 -> N1, L1 -> N1, N1, D2 -> L2, L3, N3, D3 should cluster as (L1,N1,D1), (L2,D2), (L3), (N3), (D3)
Vim-macrod into:
it should satisfy R.17 in { cluster(D1 -> N1,L1 -> N1,N1,D2 -> L2,L3,N3,D3) should equal {groups(group(L1,N1,D1),group(L2,D2),group(L3),group(N3),group(D3)))}
39
ScalaCheckThe Dogs BollocksSteep Learning Curve
object BinarySpecification extends Properties(bin) { specify(toBinary, Prop.forAllNoShrink( for{n