SlideShare a Scribd company logo
“Insulin” for Scala’s
Syntactic Diabetes
Tzach Zohar // Kenshoo // Scalapeño 2016
OR:
How to adopt Scala and
survive
source
source
Who am I
NOT Chuck Norris!
Scala “Advanced Beginner” / “Competent”
System Architect @ Kenshoo
Who’s Kenshoo
10-year Tel-Aviv based startup
Industry Leader in Digital Marketing
Java + JavaScript shop
http://kenshoo.com/
Scala @ Kenshoo
5 services written in Scala
More to come...
Internal Scala course on the go
What’s so scary?
trait GeneralizedCategory {
type U <: Hom
type =>:[A >: U#L <: U#H, B >: U#L <: U#H] = U#C[A, B]
def id[A >: U#L <: U#H]: A =>: A
def compose[A >: U#L <: U#H, B >: U#L <: U#H, C >: U#L <: U#H](
f: B =>: C, g: A =>: B): A =>: C
def *[UY<:Hom](that : GeneralizedCategory {type U=UY}) =
Category.ProductCategory[U,UY](this,that)
}
source
source
source
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
Now for some sane examples
source
val tuples = List((1, 374), (3, 42), (5, 693))
val ids = tuples.map(_._1)
val ids = tuples.map(tuple => tuple._1)
val ids = tuples.map { tuple => tuple._1 }
val tuples = List((1, 374), (3, 42), (5, 693))
val ids = tuples.map(_._1)
val ids = tuples.map(tuple => tuple._1)
val ids = tuples.map { tuple => tuple._1 }
val ids = tuples.map(t => t match { case (id, value)=> id })
val ids = tuples.map(_ match { case (id, value) => id })
val ids = tuples.map({ case (id, value) => id })
val ids = tuples.map { case (id, value) => id }
val ids = tuples.map { case (id, _) => id }
case class Profile() { … }
case class ProfileId(id: Int)
def loadProfile(profileId: ProfileId): Profile = ???
case class Profile() { … }
case class ProfileId(id: Int)
def loadProfile(profileId: ProfileId): Profile = ???
loadProfile(ProfileId(3))
loadProfile(new ProfileId(3))
loadProfile(profileId = ProfileId(3))
loadProfile(profileId = new ProfileId(3))
case class Profile() { … }
case class ProfileId(id: Int)
implicit def toId(i :Int): ProfileId = ProfileId(i)
def loadProfile(profileId: ProfileId): Profile = ???
loadProfile(ProfileId(3))
loadProfile(new ProfileId(3))
loadProfile(profileId = ProfileId(3))
loadProfile(profileId = new ProfileId(3))
loadProfile(3)
loadProfile(profileId = 3)
def loadInt(): Int = { … }
def f(value: () => Int) = { … }
f(() => 2 + loadInt())
def loadInt(): Int = { … }
def f(value: () => Int) = { … }
f(() => 2 + loadInt())
def f(value: => Int) = { … }
f(2 + loadInt())
Too Much Sugar?
source
Issues so far
Too many ways to write the same thing
Tradeoff between short and readable
Advanced features getting in the way
Insulin to the rescue
1. Style Guides
source
Style Guides
1. The basic: Official Scala-Lang Style Guide
2. The conservative: Databricks' Scala Style Guide
3. The exhaustive: Twitter's Effective Scala
4. Your own!
Style Guides
implicit def toId(i :Int): ProfileId = ProfileId(i)
loadProfile(ProfileId(3))
loadProfile(3)
“Do not use implicits to do automatic
conversions between similar datatypes”
Style Guides
“Avoid infix notation for methods
that aren't symbolic methods”
list map func
string contains "foo"
list.map(func)
string.contains("foo")
val x = y + 2
Style Guides
val ids = tuples.map(t => t match { case (id, value)=> id })
val ids = tuples.map(_ match { case (id, value) => id })
val ids = tuples.map { case (id, value) => id }
val ids = tuples.map { case (id, _) => id }
“Use pattern matching directly in function
definitions whenever applicable”
Style Guides
def f(value: => Int) = ???
f(2 + 3)
def f(value: () => Int) = ???
f(() => 2 + 3)
“Avoid using call by name.
Use () => T explicitly”
@throws[IOException]
def mightThrowException(): Int
def neverThrowsException(): Option[Int]
def neverThrowsException(): Try[Int]
def neverThrowsException(): Either[Int, String]
def neverThrowsException(): MyResult
Style Guides
“Scala provides an exception facility, but do not
use it for commonplace errors”
val ids = tuples.map(_._1)
val ids = tuples.map(tuple => tuple._1)
val ids = tuples.map { case (id, value) => id }
val ids = tuples.map { case (id, _) => id }
Style Guides
“Avoid using tuple field names
like _1, prefer pattern matching or
a dedicated case class”
2. Code Reviews
source
Code Reviews
Refer author to Style Guides
Mix “Scala Levels” - juniors should review seniors’ code
Code Reviews
Code Reviews
Code Reviews
[Only] methods which act as
accessors [...] should be declared
without parentheses, except if they
have side effects
3. Style Checkers
source
Style Checkers
Automate some of the (simpler) rules
1. Scalastyle (SBT/Gradle/Maven/Eclipse/IntelliJ)
2. Scalafmt (SBT/Vim/CLI/IntelliJ) [NEW]
⌚ 18:45:25 ➜ sbt scalastyle
[info] Loading project definition from /.../project
[info] Set current project to myProject (in build file:/.../)
[warn] MyJob.scala:31:6: parameter.number.message
[error]MyService.scala:42:6: public.methods.have.type.message
[info] Processed 42 file(s)
[info] Found 1 errors
[info] Found 2 warnings
[info] Found 0 infos
[info] Finished in 39 ms
Style Checkers
4. Scala Levels
source
Scala Levels
Application Programmer Library Designer
A1: Beginner L1: Junior
A2: Intermediate L2: Senior
A3: Expert L3: Expert
Defined by Martin Odersky in a 2011 post
Scala Levels
Application Includes
A1: Beginner Basic syntax; Simple Closures;
Collections; For-expressions; …
A2: Intermediate Pattern matching; Trait composition;
(Tail) Recursion; …
A3: Expert Folds; Streams + other lazy data
structures; Actors; …
Scala Levels
Library Includes
L1: Junior Type parameters; Traits; Lazy vals;
Currying; By-name parameters
L2: Senior Variance; Existential types; Cake Pattern;
Structural types; Extractors; …
L3: Expert Early initializers; Abstract types; Implicit
definitions; Higher-kinded types; …
source
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
source
Conclusions
1. Intermediate Scala works
(might be better than Expert Java!)
2. Style and Feature-set can
be controlled
3. No Chuck-Norrisness Required
source
Thank You

More Related Content

What's hot

Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
Heiko Behrens
 
Functional programming with Xtend
Functional programming with XtendFunctional programming with Xtend
Functional programming with Xtend
Sven Efftinge
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value Types
Péter Verhás
 
Scala’s implicits
Scala’s implicitsScala’s implicits
Scala’s implicits
Pablo Francisco Pérez Hidalgo
 
Java principles
Java principlesJava principles
Java principles
Adel Jaffan
 
Real-World Scala Design Patterns
Real-World Scala Design PatternsReal-World Scala Design Patterns
Real-World Scala Design PatternsNLJUG
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabs
brainsmartlabsedu
 
Lambdas
LambdasLambdas
Lambdas
malliksunkara
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
Java script unleashed
Java script unleashedJava script unleashed
Java script unleashed
Dibyendu Tiwary
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
SadhanaParameswaran
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
Java2Blog
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
Talha Ocakçı
 
Learn To Code: Diving deep into java
Learn To Code: Diving deep into javaLearn To Code: Diving deep into java
Learn To Code: Diving deep into java
SadhanaParameswaran
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
LivePerson
 
Tech Talk - Things I Learned at Scala Days 2013
Tech Talk - Things I Learned at Scala Days 2013Tech Talk - Things I Learned at Scala Days 2013
Tech Talk - Things I Learned at Scala Days 2013
Hung Lin
 
Applicative style programming
Applicative style programmingApplicative style programming
Applicative style programming
José Luis García Hernández
 
Introduction to functional programming with java 8
Introduction to functional programming with java 8Introduction to functional programming with java 8
Introduction to functional programming with java 8
JavaBrahman
 
Functional programming principles and Java 8
Functional programming principles and Java 8Functional programming principles and Java 8
Functional programming principles and Java 8
Dragos Balan
 
Learn To Code: Introduction to c
Learn To Code: Introduction to cLearn To Code: Introduction to c
Learn To Code: Introduction to c
SadhanaParameswaran
 

What's hot (20)

Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Functional programming with Xtend
Functional programming with XtendFunctional programming with Xtend
Functional programming with Xtend
 
Comparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value TypesComparing Golang and understanding Java Value Types
Comparing Golang and understanding Java Value Types
 
Scala’s implicits
Scala’s implicitsScala’s implicits
Scala’s implicits
 
Java principles
Java principlesJava principles
Java principles
 
Real-World Scala Design Patterns
Real-World Scala Design PatternsReal-World Scala Design Patterns
Real-World Scala Design Patterns
 
Basic online java course - Brainsmartlabs
Basic online java course  - BrainsmartlabsBasic online java course  - Brainsmartlabs
Basic online java course - Brainsmartlabs
 
Lambdas
LambdasLambdas
Lambdas
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Java script unleashed
Java script unleashedJava script unleashed
Java script unleashed
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Learn To Code: Diving deep into java
Learn To Code: Diving deep into javaLearn To Code: Diving deep into java
Learn To Code: Diving deep into java
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Tech Talk - Things I Learned at Scala Days 2013
Tech Talk - Things I Learned at Scala Days 2013Tech Talk - Things I Learned at Scala Days 2013
Tech Talk - Things I Learned at Scala Days 2013
 
Applicative style programming
Applicative style programmingApplicative style programming
Applicative style programming
 
Introduction to functional programming with java 8
Introduction to functional programming with java 8Introduction to functional programming with java 8
Introduction to functional programming with java 8
 
Functional programming principles and Java 8
Functional programming principles and Java 8Functional programming principles and Java 8
Functional programming principles and Java 8
 
Learn To Code: Introduction to c
Learn To Code: Introduction to cLearn To Code: Introduction to c
Learn To Code: Introduction to c
 

Viewers also liked

Simple, battle proven microservices strategy
Simple, battle proven microservices strategySimple, battle proven microservices strategy
Simple, battle proven microservices strategy
Erez Lotan
 
Everyone's guide to event sourcing and async-messaging
Everyone's guide to event sourcing and async-messagingEveryone's guide to event sourcing and async-messaging
Everyone's guide to event sourcing and async-messaging
Jason Swartz
 
Everyone's Guide to States, Events and Async-Messaging for Microservices
Everyone's Guide to States, Events and Async-Messaging for MicroservicesEveryone's Guide to States, Events and Async-Messaging for Microservices
Everyone's Guide to States, Events and Async-Messaging for Microservices
Jason Swartz
 
Spark Your Legacy (Spark Summit 2016)
Spark Your Legacy (Spark Summit 2016)Spark Your Legacy (Spark Summit 2016)
Spark Your Legacy (Spark Summit 2016)
Tzach Zohar
 
Coderetreat - What, Why and How
Coderetreat - What, Why and HowCoderetreat - What, Why and How
Coderetreat - What, Why and How
Erez Lotan
 
Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016
Jason Swartz
 
Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)
Chris Richardson
 
Enterprise APIs With Ease - Scala Developers of Barcelona
Enterprise APIs With Ease - Scala Developers of BarcelonaEnterprise APIs With Ease - Scala Developers of Barcelona
Enterprise APIs With Ease - Scala Developers of Barcelona
Jason Swartz
 
Why Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data WorldWhy Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data World
Dean Wampler
 
A pattern language for microservices (#SFMicroservices)
A pattern language for microservices (#SFMicroservices)A pattern language for microservices (#SFMicroservices)
A pattern language for microservices (#SFMicroservices)
Chris Richardson
 
Events on the outside, on the inside and at the core (jfokus jfokus2016)
Events on the outside, on the inside and at the core (jfokus jfokus2016)Events on the outside, on the inside and at the core (jfokus jfokus2016)
Events on the outside, on the inside and at the core (jfokus jfokus2016)
Chris Richardson
 
A microservice approach for legacy modernisation
A microservice approach for legacy modernisationA microservice approach for legacy modernisation
A microservice approach for legacy modernisation
luisw19
 
Microservices and Redis #redisconf Keynote
Microservices and Redis #redisconf KeynoteMicroservices and Redis #redisconf Keynote
Microservices and Redis #redisconf Keynote
Chris Richardson
 
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Chris Richardson
 
Developing event-driven microservices with event sourcing and CQRS (Shanghai)
Developing event-driven microservices with event sourcing and CQRS (Shanghai)Developing event-driven microservices with event sourcing and CQRS (Shanghai)
Developing event-driven microservices with event sourcing and CQRS (Shanghai)
Chris Richardson
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)
Chris Richardson
 
REST and Microservices
REST and MicroservicesREST and Microservices
REST and Microservices
Shaun Abram
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Chris Richardson
 
Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...
Chris Richardson
 
MicroService Architecture
MicroService ArchitectureMicroService Architecture
MicroService Architecture
Fred George
 

Viewers also liked (20)

Simple, battle proven microservices strategy
Simple, battle proven microservices strategySimple, battle proven microservices strategy
Simple, battle proven microservices strategy
 
Everyone's guide to event sourcing and async-messaging
Everyone's guide to event sourcing and async-messagingEveryone's guide to event sourcing and async-messaging
Everyone's guide to event sourcing and async-messaging
 
Everyone's Guide to States, Events and Async-Messaging for Microservices
Everyone's Guide to States, Events and Async-Messaging for MicroservicesEveryone's Guide to States, Events and Async-Messaging for Microservices
Everyone's Guide to States, Events and Async-Messaging for Microservices
 
Spark Your Legacy (Spark Summit 2016)
Spark Your Legacy (Spark Summit 2016)Spark Your Legacy (Spark Summit 2016)
Spark Your Legacy (Spark Summit 2016)
 
Coderetreat - What, Why and How
Coderetreat - What, Why and HowCoderetreat - What, Why and How
Coderetreat - What, Why and How
 
Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016
 
Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)
 
Enterprise APIs With Ease - Scala Developers of Barcelona
Enterprise APIs With Ease - Scala Developers of BarcelonaEnterprise APIs With Ease - Scala Developers of Barcelona
Enterprise APIs With Ease - Scala Developers of Barcelona
 
Why Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data WorldWhy Scala Is Taking Over the Big Data World
Why Scala Is Taking Over the Big Data World
 
A pattern language for microservices (#SFMicroservices)
A pattern language for microservices (#SFMicroservices)A pattern language for microservices (#SFMicroservices)
A pattern language for microservices (#SFMicroservices)
 
Events on the outside, on the inside and at the core (jfokus jfokus2016)
Events on the outside, on the inside and at the core (jfokus jfokus2016)Events on the outside, on the inside and at the core (jfokus jfokus2016)
Events on the outside, on the inside and at the core (jfokus jfokus2016)
 
A microservice approach for legacy modernisation
A microservice approach for legacy modernisationA microservice approach for legacy modernisation
A microservice approach for legacy modernisation
 
Microservices and Redis #redisconf Keynote
Microservices and Redis #redisconf KeynoteMicroservices and Redis #redisconf Keynote
Microservices and Redis #redisconf Keynote
 
Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)Developing functional domain models with event sourcing (sbtb, sbtb2015)
Developing functional domain models with event sourcing (sbtb, sbtb2015)
 
Developing event-driven microservices with event sourcing and CQRS (Shanghai)
Developing event-driven microservices with event sourcing and CQRS (Shanghai)Developing event-driven microservices with event sourcing and CQRS (Shanghai)
Developing event-driven microservices with event sourcing and CQRS (Shanghai)
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)
 
REST and Microservices
REST and MicroservicesREST and Microservices
REST and Microservices
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
 
Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...Microservices: Decomposing Applications for Deployability and Scalability (ja...
Microservices: Decomposing Applications for Deployability and Scalability (ja...
 
MicroService Architecture
MicroService ArchitectureMicroService Architecture
MicroService Architecture
 

Similar to “Insulin” for Scala’s Syntactic Diabetes

Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Michael Stal
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
Michael Stal
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Lorenzo Dematté
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
Alfonso Ruzafa
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
Mark Wilkinson
 
The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala Makeover
Garth Gilmour
 
Thea: Processing OWL Ontologies - An application of logic programming
Thea: Processing OWL Ontologies - An application of logic programmingThea: Processing OWL Ontologies - An application of logic programming
Thea: Processing OWL Ontologies - An application of logic programming
guest57f623bf
 
Processing OWL2 Ontologies using Thea: An application of Logic Programming
Processing OWL2 Ontologies using Thea: An application of Logic ProgrammingProcessing OWL2 Ontologies using Thea: An application of Logic Programming
Processing OWL2 Ontologies using Thea: An application of Logic Programming
Vangelis Vassiliadis
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
parveen837153
 
Let's refine your Scala Code
Let's refine your Scala CodeLet's refine your Scala Code
Let's refine your Scala Code
Tech Triveni
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
Intelligo Technologies
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
Intelligo Technologies
 
core java
 core java core java
core java
dssreenath
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
caswenson
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
Ostap Andrusiv
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
Łukasz Bałamut
 

Similar to “Insulin” for Scala’s Syntactic Diabetes (20)

Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
SADI in Perl - Protege Plugin Tutorial (fixed Aug 24, 2011)
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala Makeover
 
Thea: Processing OWL Ontologies - An application of logic programming
Thea: Processing OWL Ontologies - An application of logic programmingThea: Processing OWL Ontologies - An application of logic programming
Thea: Processing OWL Ontologies - An application of logic programming
 
Processing OWL2 Ontologies using Thea: An application of Logic Programming
Processing OWL2 Ontologies using Thea: An application of Logic ProgrammingProcessing OWL2 Ontologies using Thea: An application of Logic Programming
Processing OWL2 Ontologies using Thea: An application of Logic Programming
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
Let's refine your Scala Code
Let's refine your Scala CodeLet's refine your Scala Code
Let's refine your Scala Code
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Java tutorial PPT
Java tutorial  PPTJava tutorial  PPT
Java tutorial PPT
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
core java
 core java core java
core java
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 

Recently uploaded

Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 

Recently uploaded (20)

Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 

“Insulin” for Scala’s Syntactic Diabetes

  • 1. “Insulin” for Scala’s Syntactic Diabetes Tzach Zohar // Kenshoo // Scalapeño 2016
  • 2. OR: How to adopt Scala and survive source
  • 3.
  • 5. Who am I NOT Chuck Norris! Scala “Advanced Beginner” / “Competent” System Architect @ Kenshoo
  • 6. Who’s Kenshoo 10-year Tel-Aviv based startup Industry Leader in Digital Marketing Java + JavaScript shop http://kenshoo.com/
  • 7. Scala @ Kenshoo 5 services written in Scala More to come... Internal Scala course on the go
  • 9. trait GeneralizedCategory { type U <: Hom type =>:[A >: U#L <: U#H, B >: U#L <: U#H] = U#C[A, B] def id[A >: U#L <: U#H]: A =>: A def compose[A >: U#L <: U#H, B >: U#L <: U#H, C >: U#L <: U#H]( f: B =>: C, g: A =>: B): A =>: C def *[UY<:Hom](that : GeneralizedCategory {type U=UY}) = Category.ProductCategory[U,UY](this,that) } source
  • 11. source def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
  • 12. Now for some sane examples source
  • 13. val tuples = List((1, 374), (3, 42), (5, 693)) val ids = tuples.map(_._1) val ids = tuples.map(tuple => tuple._1) val ids = tuples.map { tuple => tuple._1 }
  • 14. val tuples = List((1, 374), (3, 42), (5, 693)) val ids = tuples.map(_._1) val ids = tuples.map(tuple => tuple._1) val ids = tuples.map { tuple => tuple._1 } val ids = tuples.map(t => t match { case (id, value)=> id }) val ids = tuples.map(_ match { case (id, value) => id }) val ids = tuples.map({ case (id, value) => id }) val ids = tuples.map { case (id, value) => id } val ids = tuples.map { case (id, _) => id }
  • 15. case class Profile() { … } case class ProfileId(id: Int) def loadProfile(profileId: ProfileId): Profile = ???
  • 16. case class Profile() { … } case class ProfileId(id: Int) def loadProfile(profileId: ProfileId): Profile = ??? loadProfile(ProfileId(3)) loadProfile(new ProfileId(3)) loadProfile(profileId = ProfileId(3)) loadProfile(profileId = new ProfileId(3))
  • 17. case class Profile() { … } case class ProfileId(id: Int) implicit def toId(i :Int): ProfileId = ProfileId(i) def loadProfile(profileId: ProfileId): Profile = ??? loadProfile(ProfileId(3)) loadProfile(new ProfileId(3)) loadProfile(profileId = ProfileId(3)) loadProfile(profileId = new ProfileId(3)) loadProfile(3) loadProfile(profileId = 3)
  • 18. def loadInt(): Int = { … } def f(value: () => Int) = { … } f(() => 2 + loadInt())
  • 19. def loadInt(): Int = { … } def f(value: () => Int) = { … } f(() => 2 + loadInt()) def f(value: => Int) = { … } f(2 + loadInt())
  • 21. Issues so far Too many ways to write the same thing Tradeoff between short and readable Advanced features getting in the way
  • 22. Insulin to the rescue
  • 24. Style Guides 1. The basic: Official Scala-Lang Style Guide 2. The conservative: Databricks' Scala Style Guide 3. The exhaustive: Twitter's Effective Scala 4. Your own!
  • 25. Style Guides implicit def toId(i :Int): ProfileId = ProfileId(i) loadProfile(ProfileId(3)) loadProfile(3) “Do not use implicits to do automatic conversions between similar datatypes”
  • 26. Style Guides “Avoid infix notation for methods that aren't symbolic methods” list map func string contains "foo" list.map(func) string.contains("foo") val x = y + 2
  • 27. Style Guides val ids = tuples.map(t => t match { case (id, value)=> id }) val ids = tuples.map(_ match { case (id, value) => id }) val ids = tuples.map { case (id, value) => id } val ids = tuples.map { case (id, _) => id } “Use pattern matching directly in function definitions whenever applicable”
  • 28. Style Guides def f(value: => Int) = ??? f(2 + 3) def f(value: () => Int) = ??? f(() => 2 + 3) “Avoid using call by name. Use () => T explicitly”
  • 29. @throws[IOException] def mightThrowException(): Int def neverThrowsException(): Option[Int] def neverThrowsException(): Try[Int] def neverThrowsException(): Either[Int, String] def neverThrowsException(): MyResult Style Guides “Scala provides an exception facility, but do not use it for commonplace errors”
  • 30. val ids = tuples.map(_._1) val ids = tuples.map(tuple => tuple._1) val ids = tuples.map { case (id, value) => id } val ids = tuples.map { case (id, _) => id } Style Guides “Avoid using tuple field names like _1, prefer pattern matching or a dedicated case class”
  • 32. Code Reviews Refer author to Style Guides Mix “Scala Levels” - juniors should review seniors’ code
  • 35. Code Reviews [Only] methods which act as accessors [...] should be declared without parentheses, except if they have side effects
  • 37. Style Checkers Automate some of the (simpler) rules 1. Scalastyle (SBT/Gradle/Maven/Eclipse/IntelliJ) 2. Scalafmt (SBT/Vim/CLI/IntelliJ) [NEW]
  • 38. ⌚ 18:45:25 ➜ sbt scalastyle [info] Loading project definition from /.../project [info] Set current project to myProject (in build file:/.../) [warn] MyJob.scala:31:6: parameter.number.message [error]MyService.scala:42:6: public.methods.have.type.message [info] Processed 42 file(s) [info] Found 1 errors [info] Found 2 warnings [info] Found 0 infos [info] Finished in 39 ms Style Checkers
  • 40. Scala Levels Application Programmer Library Designer A1: Beginner L1: Junior A2: Intermediate L2: Senior A3: Expert L3: Expert Defined by Martin Odersky in a 2011 post
  • 41. Scala Levels Application Includes A1: Beginner Basic syntax; Simple Closures; Collections; For-expressions; … A2: Intermediate Pattern matching; Trait composition; (Tail) Recursion; … A3: Expert Folds; Streams + other lazy data structures; Actors; …
  • 42. Scala Levels Library Includes L1: Junior Type parameters; Traits; Lazy vals; Currying; By-name parameters L2: Senior Variance; Existential types; Cake Pattern; Structural types; Extractors; … L3: Expert Early initializers; Abstract types; Implicit definitions; Higher-kinded types; …
  • 43. source def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
  • 46. 1. Intermediate Scala works (might be better than Expert Java!) 2. Style and Feature-set can be controlled 3. No Chuck-Norrisness Required source