SlideShare uma empresa Scribd logo
1 de 42
Scala @ TomTom Eric Bowman eric.bowman@tomtom.com 26 May 2010
What’s He Building In There? Not just PNDs Traffic Services Location Services Address & Local Search Tons of Data -> Tons of Analysis Deep Commitment to Server-Side Java 2
3
4
5 Company Confidential ,[object Object]
40 reams of paper
5 laptops
8 keyboards
1 back operation
30,000 strands of hair,[object Object]
7
Tutorial on Good Lisp Programming Style 8 “Most algorithms can be characterized as: ,[object Object]
  Sorting (sort merge remove-duplicates)
  Filtering (remove remove-if mapcan)
  Mapping (map mapcarmapc)
  Combining (reduce mapcan)
  Counting (count count-if)These functions abstract common control patterns. Code that uses them is: ,[object Object]
  Self-documenting
  Easy to understand
  Often reusable
  Usually efficient”    From Peter Norvig’sTutorial on Good Lisp Programming Style, 1993          (http://www.norvig.com/luv-slides.ps)
But... “Lisp is good for: Exploratory programming Rapid prototyping Minimizing time-to-market Single-programmer (or single-digit team) projects Source-to-source or data-to-data transformation” (ibid.) 9
I Like Static types Refactoring Tools Lazy Sundays Paying Some Kid To Cut The Grass Spreadsheets Not Flying The Plane 10
What is this Scala thing? 11
Scala Is... An escaped research language from EPFL targeting JVM and CLR Object-oriented and functional Statically typed Lisp, ML, Haskell, Erlang, etc. DSL-friendly 12
Bi-Scalar Disorder 13
Functional Programming? Functions as first class objects Immutability Closures Binding free variables to enclosing lexical scope  Higher-order Functions functions as input and/or output A different set of idioms... 14
Keep Back for (int i = 1; i <= 256; i++) {    if (array[i-1] == ... 15
LOLCrash 16
Idioms Reduce cognitive overhead Reduce bugs Make intention clear Mini-Patterns 17
Java Idioms ++C++ No more 0xDEADBEEF Leads to lots of loops and copies, if you’re doing it right Hard programs get complex doing common things Nested loops begin to look Harmful... 18
19
For Comprehensions for(inti=0; i<100; i++) { ... } for (i <- 0 until 100) {  ... /* do something with i */ } (0.until(100)).foreach(i =>  			/* something with i */) 20
For Comprehensions Lists algorithmic “sweet spot” Syntactic Sugar for: foreach map filter flatMap 21
The Easy Ones for (i <- 1 to 6) yield i * 2 (1 to 6).map(_ * 2) 	(2,4,6,8,10,12) for (i <- 1 to 6 if i % 2 == 0) yield i (1 to 6).filter(_ % 2 == 0) 	(2,4,6) for (i <- 1 to 6) { println(i + “ “) } (1 to 6).foreach { i => print(i + “ “) } 	1 2 3 4 5 6 22
A Harder One... List<Integer> array = new ArrayList<Integer>(); for (i = 1; i <= 3; i++) {   for (j = i; j <= 3; j++) { array.add(j);   } } System.out.println(array); [1, 2, 3, 2, 3, 3] for (i <- 1 to 3; j <- i to 3) yield j (1, 2, 3, 2, 3, 3) (1 to 3).flatMap(i => (i to 3).map(j => j))    23
flatMap Subtle thing... “Applies the given function f to each element, then concatenates the results” Turns a list of lists into a list List(List(1,2,3), List(4,5,6)).flatMap(x => x) List(1, 2, 3, 4, 5, 6) List(“tom”, “tom”).flatMap(_.capitalize).mkString TomTom “Special sauce” for nested looping constructs (Equivalent to Haskell’s monadic “bind”) 24
IteratorIterator package org.hyperic.sigar.util;  public static class IteratorIteratorimplements java.util.Iterator {  private java.util.ArrayListiterators;  public IteratorIterator() {}  public void add(java.util.Iteratoriterator) {}  public booleanhasNext() {}  public java.lang.Object next() {}  	public void remove() {}  } 25
flatMapflatMap def foo(arg: Iterable[Int]) {     ... Do something with arg } val some: Iterable[Int] = getSomeIterable foo(some) val more: Iterable[Int] = getMore foo(List(some, more).flatMap(x => x)) 26
Real-Life Example “mntstamarg” Each term has aliases Need all permutations 27
Java Version static List<String> aliasReplace(String place) {          String[] bits = nospaces.split(place);          List<String> result = new ArrayList<String>();          List<StringBuilder> allAliases = new ArrayList<StringBuilder>();  for (String bit : bits) {              String[] ales = aliases.get(bit);  if (ales != null) {  	            if (allAliases.size() == 0) {  allAliases.add(new StringBuilder(bit));  for (String alias : ales) {  allAliases.add(new StringBuilder(alias));                      }                  }  else {                      List<StringBuilder> clones = new               ArrayList<StringBuilder>();  for (StringBuilder a : allAliases) {  clones.add(new StringBuilder(a).append(" ").append(                                  bit));  for (String alias : ales) {  clones.add(new StringBuilder(a).append(" ").append(                                      alias));                          }                      }  allAliases = clones;                  }              }  else {  if (allAliases.size() == 0) {  allAliases.add(new StringBuilder(bit));                  }  else {  for (StringBuilder b : allAliases) {  b.append(" ").append(bit);                      }                  }              }          }  for (StringBuildermunge: allAliases) {  result.add(munge.toString());          }  return result;      } 28
29

Mais conteúdo relacionado

Mais procurados

Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data scienceJohn Cant
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Platonov Sergey
 
The Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemThe Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemJohn De Goes
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance PythonIan Ozsvald
 
Introduction to functional programming using Ocaml
Introduction to functional programming using OcamlIntroduction to functional programming using Ocaml
Introduction to functional programming using Ocamlpramode_ce
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...GECon_Org Team
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allYauheni Akhotnikau
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance PuzzlersDoug Hawkins
 
Orthogonal Functional Architecture
Orthogonal Functional ArchitectureOrthogonal Functional Architecture
Orthogonal Functional ArchitectureJohn De Goes
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayKevlin Henney
 
Halogen: Past, Present, and Future
Halogen: Past, Present, and FutureHalogen: Past, Present, and Future
Halogen: Past, Present, and FutureJohn De Goes
 
Taming Asynchronous Transforms with Interstellar
Taming Asynchronous Transforms with InterstellarTaming Asynchronous Transforms with Interstellar
Taming Asynchronous Transforms with InterstellarJens Ravens
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsJohn De Goes
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей КоваленкоFwdays
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...Philip Schwarz
 
Lambda выражения и Java 8
Lambda выражения и Java 8Lambda выражения и Java 8
Lambda выражения и Java 8Alex Tumanoff
 

Mais procurados (20)

Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
The Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect SystemThe Design of the Scalaz 8 Effect System
The Design of the Scalaz 8 Effect System
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 
Introduction to functional programming using Ocaml
Introduction to functional programming using OcamlIntroduction to functional programming using Ocaml
Introduction to functional programming using Ocaml
 
Fun with Kotlin
Fun with KotlinFun with Kotlin
Fun with Kotlin
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...GECon2017_Cpp  a monster that no one likes but that will outlast them all _Ya...
GECon2017_Cpp a monster that no one likes but that will outlast them all _Ya...
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 
Orthogonal Functional Architecture
Orthogonal Functional ArchitectureOrthogonal Functional Architecture
Orthogonal Functional Architecture
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 
Halogen: Past, Present, and Future
Halogen: Past, Present, and FutureHalogen: Past, Present, and Future
Halogen: Past, Present, and Future
 
Taming Asynchronous Transforms with Interstellar
Taming Asynchronous Transforms with InterstellarTaming Asynchronous Transforms with Interstellar
Taming Asynchronous Transforms with Interstellar
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко"Немного о функциональном программирование в JavaScript" Алексей Коваленко
"Немного о функциональном программирование в JavaScript" Алексей Коваленко
 
Sneaking inside Kotlin features
Sneaking inside Kotlin featuresSneaking inside Kotlin features
Sneaking inside Kotlin features
 
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...The Functional Programming Triad of Folding, Scanning and Iteration - a first...
The Functional Programming Triad of Folding, Scanning and Iteration - a first...
 
Lambda выражения и Java 8
Lambda выражения и Java 8Lambda выражения и Java 8
Lambda выражения и Java 8
 

Destaque

TomTom Q1 2014 Financial Results
TomTom Q1 2014 Financial ResultsTomTom Q1 2014 Financial Results
TomTom Q1 2014 Financial ResultsLudovic Privat
 
Allan Rasmussen TomTom Maps June 16th 2014 - INSPIRE Conference
Allan Rasmussen TomTom Maps June 16th 2014 - INSPIRE ConferenceAllan Rasmussen TomTom Maps June 16th 2014 - INSPIRE Conference
Allan Rasmussen TomTom Maps June 16th 2014 - INSPIRE ConferenceLudovic Privat
 
TomTom Presentation.
TomTom Presentation.TomTom Presentation.
TomTom Presentation.alfiepanda
 
Mba Tomtom merger TeleAtlas
Mba Tomtom merger TeleAtlasMba Tomtom merger TeleAtlas
Mba Tomtom merger TeleAtlasRoel_Kock
 

Destaque (7)

TomTom Q1 2014 Financial Results
TomTom Q1 2014 Financial ResultsTomTom Q1 2014 Financial Results
TomTom Q1 2014 Financial Results
 
Allan Rasmussen TomTom Maps June 16th 2014 - INSPIRE Conference
Allan Rasmussen TomTom Maps June 16th 2014 - INSPIRE ConferenceAllan Rasmussen TomTom Maps June 16th 2014 - INSPIRE Conference
Allan Rasmussen TomTom Maps June 16th 2014 - INSPIRE Conference
 
Tom Tom
Tom TomTom Tom
Tom Tom
 
TOM TOM
TOM TOMTOM TOM
TOM TOM
 
TomTom Presentation.
TomTom Presentation.TomTom Presentation.
TomTom Presentation.
 
Mba Tomtom merger TeleAtlas
Mba Tomtom merger TeleAtlasMba Tomtom merger TeleAtlas
Mba Tomtom merger TeleAtlas
 
TomTom Dynamic Routing
TomTom Dynamic RoutingTomTom Dynamic Routing
TomTom Dynamic Routing
 

Semelhante a Scala @ TomTom

Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lispkyleburton
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesGanesh Samarthyam
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scalaparag978978
 
JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersTikal Knowledge
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0Yaser Zhian
 

Semelhante a Scala @ TomTom (20)

Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Groovy
GroovyGroovy
Groovy
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Monadologie
MonadologieMonadologie
Monadologie
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scala
 
JBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java ProgrammersJBUG 11 - Scala For Java Programmers
JBUG 11 - Scala For Java Programmers
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 

Último

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
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
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 

Último (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
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
 
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...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Scala @ TomTom

  • 1. Scala @ TomTom Eric Bowman eric.bowman@tomtom.com 26 May 2010
  • 2. What’s He Building In There? Not just PNDs Traffic Services Location Services Address & Local Search Tons of Data -> Tons of Analysis Deep Commitment to Server-Side Java 2
  • 3. 3
  • 4. 4
  • 5.
  • 6. 40 reams of paper
  • 10.
  • 11. 7
  • 12.
  • 13. Sorting (sort merge remove-duplicates)
  • 14. Filtering (remove remove-if mapcan)
  • 15. Mapping (map mapcarmapc)
  • 16. Combining (reduce mapcan)
  • 17.
  • 19. Easy to understand
  • 20. Often reusable
  • 21. Usually efficient” From Peter Norvig’sTutorial on Good Lisp Programming Style, 1993 (http://www.norvig.com/luv-slides.ps)
  • 22. But... “Lisp is good for: Exploratory programming Rapid prototyping Minimizing time-to-market Single-programmer (or single-digit team) projects Source-to-source or data-to-data transformation” (ibid.) 9
  • 23. I Like Static types Refactoring Tools Lazy Sundays Paying Some Kid To Cut The Grass Spreadsheets Not Flying The Plane 10
  • 24. What is this Scala thing? 11
  • 25. Scala Is... An escaped research language from EPFL targeting JVM and CLR Object-oriented and functional Statically typed Lisp, ML, Haskell, Erlang, etc. DSL-friendly 12
  • 27. Functional Programming? Functions as first class objects Immutability Closures Binding free variables to enclosing lexical scope Higher-order Functions functions as input and/or output A different set of idioms... 14
  • 28. Keep Back for (int i = 1; i <= 256; i++) { if (array[i-1] == ... 15
  • 30. Idioms Reduce cognitive overhead Reduce bugs Make intention clear Mini-Patterns 17
  • 31. Java Idioms ++C++ No more 0xDEADBEEF Leads to lots of loops and copies, if you’re doing it right Hard programs get complex doing common things Nested loops begin to look Harmful... 18
  • 32. 19
  • 33. For Comprehensions for(inti=0; i<100; i++) { ... } for (i <- 0 until 100) { ... /* do something with i */ } (0.until(100)).foreach(i => /* something with i */) 20
  • 34. For Comprehensions Lists algorithmic “sweet spot” Syntactic Sugar for: foreach map filter flatMap 21
  • 35. The Easy Ones for (i <- 1 to 6) yield i * 2 (1 to 6).map(_ * 2) (2,4,6,8,10,12) for (i <- 1 to 6 if i % 2 == 0) yield i (1 to 6).filter(_ % 2 == 0) (2,4,6) for (i <- 1 to 6) { println(i + “ “) } (1 to 6).foreach { i => print(i + “ “) } 1 2 3 4 5 6 22
  • 36. A Harder One... List<Integer> array = new ArrayList<Integer>(); for (i = 1; i <= 3; i++) { for (j = i; j <= 3; j++) { array.add(j); } } System.out.println(array); [1, 2, 3, 2, 3, 3] for (i <- 1 to 3; j <- i to 3) yield j (1, 2, 3, 2, 3, 3) (1 to 3).flatMap(i => (i to 3).map(j => j)) 23
  • 37. flatMap Subtle thing... “Applies the given function f to each element, then concatenates the results” Turns a list of lists into a list List(List(1,2,3), List(4,5,6)).flatMap(x => x) List(1, 2, 3, 4, 5, 6) List(“tom”, “tom”).flatMap(_.capitalize).mkString TomTom “Special sauce” for nested looping constructs (Equivalent to Haskell’s monadic “bind”) 24
  • 38. IteratorIterator package org.hyperic.sigar.util; public static class IteratorIteratorimplements java.util.Iterator { private java.util.ArrayListiterators; public IteratorIterator() {} public void add(java.util.Iteratoriterator) {} public booleanhasNext() {} public java.lang.Object next() {} public void remove() {} } 25
  • 39. flatMapflatMap def foo(arg: Iterable[Int]) { ... Do something with arg } val some: Iterable[Int] = getSomeIterable foo(some) val more: Iterable[Int] = getMore foo(List(some, more).flatMap(x => x)) 26
  • 40. Real-Life Example “mntstamarg” Each term has aliases Need all permutations 27
  • 41. Java Version static List<String> aliasReplace(String place) { String[] bits = nospaces.split(place); List<String> result = new ArrayList<String>(); List<StringBuilder> allAliases = new ArrayList<StringBuilder>(); for (String bit : bits) { String[] ales = aliases.get(bit); if (ales != null) { if (allAliases.size() == 0) { allAliases.add(new StringBuilder(bit)); for (String alias : ales) { allAliases.add(new StringBuilder(alias)); } } else { List<StringBuilder> clones = new ArrayList<StringBuilder>(); for (StringBuilder a : allAliases) { clones.add(new StringBuilder(a).append(" ").append( bit)); for (String alias : ales) { clones.add(new StringBuilder(a).append(" ").append( alias)); } } allAliases = clones; } } else { if (allAliases.size() == 0) { allAliases.add(new StringBuilder(bit)); } else { for (StringBuilder b : allAliases) { b.append(" ").append(bit); } } } } for (StringBuildermunge: allAliases) { result.add(munge.toString()); } return result; } 28
  • 42. 29
  • 43. Scala Version def alias(query: String, aliases: String => List[String]): List[String] = { def recurse(prefix: List[String], remainder: List[String]): List[List[String]] = { remainder match { case Nil => prefix :: Nil case head :: tail => aliases(head).flatMap(term => recurse(term :: prefix, tail)) } recurse(Nil,query.split(“s”).toList.reverse).map( _.mkString(“ “)) } 30
  • 44. 31
  • 45. Yeah yeahyeah but “Perl 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 Hopkins If it compiles, it nearly works. Really. Visual Plane-Oriented Programming I ♥ Idioms “But in Java, each little part is so very simple...” 32
  • 46. 33
  • 48. “Weak developers will move heaven and earth to do the wrong thing. You can’t limit the damage they do by locking up the sharp tools. They’ll just swing the blunt tools harder.” – Glenn Vandenburg 35
  • 49. @TomTom Testing Middleware “Smart Content Switch” We needed it quickly... B2B/B2G Traffic Query Engine Clustering Algorithm DSL Templating Engine Content Cleanup Next-Generation Geocoder 36
  • 50. How To Sneak It In Start with Testing ScalaCheckIS AWESOME. Specs, ScalaTest testing DSLs Start with something low risk Ok, well, we didn’t do that Prepare for steep learning curve ...followed by a productivity hockey stick 37
  • 51. Another Example 8000 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 hope 38
  • 52. Testing Functional 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-macro’d 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
  • 53. ScalaCheck The Dog’s Bollocks Steep Learning Curve object BinarySpecification extends Properties(“bin”) { specify(“toBinary”, Prop.forAllNoShrink( for{n <- Gen.choose(0d, 0.99999999d) m <- Gen.choose(20,31) } yield Pair(n, m)) { p => Math.abs(toDecimal(toBinary(p._1, p._2)) – p._1 < 1e-10 })} 40
  • 54. So little time... Traits Case classes Pattern matching Structural types Self types XML Option Covariance/Contravariance @specialized 41
  • 55. This slide left intentionally blank.