SlideShare a Scribd company logo
1 of 52
Download to read offline
MADRID · MAR · 2015
Scala Programming @ Madrid
Scala
David Vallejo & Javier Santos
MADRID · MAR · 2015
Scala Programming @ Madrid
About us
Javier Santos @jpaniego
«Hay dos formas de programar sin
errores; solo la tercera funciona»
Alan J Perlis
David Vallejo @dvnavarro
«Una expresión regular es una
expresión que no es del todo buena,
pero tampoco del todo mala.»
@borjamonserrano
MADRID · MAR · 2015
Scala Programming @ Madrid
What’s Scala?
According Wikipedia:
Scala (/ˈskɑːlə/ SKAH-lə)[6] is an object-functional[7] programming language for general software
applications. Scala has full support for functional programming and a very strong static type system. This
allows programs written in Scala to be very concise and thus smaller in size than other general-purpose
programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings
of Java.[5]
MADRID · MAR · 2015
Scala Programming @ Madrid
What’s Scala?
According to the official website:
MADRID · MAR · 2015
Scala Programming @ Madrid
What’s Scala?
According to newbies:
MADRID · MAR · 2015
Scala Programming @ Madrid
What’s Scala?
● General purpose language that runs on the JVM.
● Martin Odersky
● Multiple Inheritance
● Multi-paradigm: functional & object-oriented
● Typesafe (2011)
● TIOBE (41st position)
MADRID · MAR · 2015
Scala Programming @ Madrid
Why so fashionable these days?
● Useful tools to build concurrent systems
○ More cores, more concurrency
○ Avoid side effects using functional programming and immutable values
○ Actor paradigm with the toolkit called Akka
● Awesome frameworks and tool-kits: Play Framework, Akka, Spark, Spray ...
● Others
○ Powerful mechanisms for embedding DSL like, for example, implicits
○ The best of functional world and the best of OO world
○ Elegant & concise
MADRID · MAR · 2015
Scala Programming @ Madrid
Who uses it?
MADRID · MAR · 2015
Scala Programming @ Madrid
Developer environment
● REPL (Read-eval-print loop)
http://scala-lang.org/download/
● SBT
http://www.scala-sbt.org/
● IDES:
Eclipse http://scala-ide.org/download/sdk.html
Intellij https://www.jetbrains.com/idea/features/scala.html
NetBeans http://wiki.netbeans.org/Scala
MADRID · MAR · 2015
Scala Programming @ Madrid
Features
MADRID · MAR · 2015
Scala Programming @ Madrid
val vs var
● Type inference
● var: variables (mutable)
● val: values (immutable)
● lazy vals: Not evaluated until necessary
MADRID · MAR · 2015
Scala Programming @ Madrid
val vs var
● vals are always immutable?
Stateful objects (mutable collections for example) (watch out with side effects)
MADRID · MAR · 2015
Scala Programming @ Madrid
Methods/functions
● Type inference
● Only braces means Unit
● No return necessary
● Variable args number (*)
MADRID · MAR · 2015
Scala Programming @ Madrid
What about class?
● A class may contain
○ attributes (var/val)
○ methods (def)
○ expressions that
will be evaluated
at instantiation time.
MADRID · MAR · 2015
Scala Programming @ Madrid
What about class?
● A simple class with no parameters
MADRID · MAR · 2015
Scala Programming @ Madrid
What about class?
● A simple class with parameters
MADRID · MAR · 2015
Scala Programming @ Madrid
What about class?
● A simple class with parameter accessors
MADRID · MAR · 2015
Scala Programming @ Madrid
What about abstract class?
● It cannot be instantiated, unless ...
MADRID · MAR · 2015
Scala Programming @ Madrid
What about case class?
● A case class provides:
○ parameter accessors
○ companion object with apply and unapply
○ extends from Serializable
○ copy method
● ...but it cannot be extended (We can handle that)
MADRID · MAR · 2015
Scala Programming @ Madrid
What about case class?
MADRID · MAR · 2015
Scala Programming @ Madrid
MADRID · MAR · 2015
Scala Programming @ Madrid
Rich interfaces: trait
● Methods can be implemented.
● Multiple inheritance.
MADRID · MAR · 2015
Scala Programming @ Madrid
Inheritance: mixing in stuff...
● Linearization (Watch out the order)
MADRID · MAR · 2015
Scala Programming @ Madrid
What about nulls in Scala?
● Use option instead
● Two possible values: Some(t) and None
MADRID · MAR · 2015
Scala Programming @ Madrid
Options in Scala
● Besides it’s iterable!
● Nice functional methods like fold.
MADRID · MAR · 2015
Scala Programming @ Madrid
Generics
● For classes and traits
MADRID · MAR · 2015
Scala Programming @ Madrid
Generics
● For methods
MADRID · MAR · 2015
Scala Programming @ Madrid
Generics
● Variance: C[T] != C[+T] != C[-T]
MADRID · MAR · 2015
Scala Programming @ Madrid
Conditional statements: if
MADRID · MAR · 2015
Scala Programming @ Madrid
Conditional statements: match
● Similar to a Java switch...
MADRID · MAR · 2015
Scala Programming @ Madrid
Conditional statements: match
● ...except that it’s not only a switch :-)
● Pattern matching.
MADRID · MAR · 2015
Scala Programming @ Madrid
Conditional statements: match
● So it’s great, but be carefull with
MADRID · MAR · 2015
Scala Programming @ Madrid
Loop statements: while
● Not very commonly used (vars and so on…)
MADRID · MAR · 2015
Scala Programming @ Madrid
Loop statements: for
● for-comprehensions: syntactic sugar for
MADRID · MAR · 2015
Scala Programming @ Madrid
Loop statements: for
● Typical example:
Is this purely functional?
MADRID · MAR · 2015
Scala Programming @ Madrid
Loops in Scala
MADRID · MAR · 2015
Scala Programming @ Madrid
Your new friend: fold
● Two signatures: foldLeft and foldRight (iterative vs. recursive)
● Same example:
MADRID · MAR · 2015
Scala Programming @ Madrid
Other common friends: map
● Convert each element to another (or same) type.
● Example:
MADRID · MAR · 2015
Scala Programming @ Madrid
Other common friends: flatMap
● Map each element to some monad-like type and flatten them
● Example:
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Type alias
● Useful for specifying anonymous tuple types
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Higher order functions
● Javascript ninjas gonna like…
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Higher order functions
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Higher order functions
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Infix notation, semicolon inference...
● Allows writing readable code
● Specially useful for DSLs.
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Infix notation, semicolon inference...
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Implicits
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Implicits
● Defined by scope (be careful with ambiguity)
● Specially difficult to trace: use only in very located places
MADRID · MAR · 2015
Scala Programming @ Madrid
More cool stuff: Self types
● Used for disambiguating with duplicated val/function names
MADRID · MAR · 2015
Scala Programming @ Madrid
Conclusions
● Steep learning curve
● It's hard to know which is the best way to do something
● Language expanding. More and more Scala enthusiasts.
● Mix the functional world and the OO world :)
MADRID · MAR · 2015
Scala Programming @ Madrid
MADRID · MAR · 2015
Scala Programming @ Madrid
Scala
David Vallejo & Javier Santos
MADRID · MAR · 2015
Scala Programming @ Madrid
scalerablog.wordpress.com
@scalerablog

More Related Content

What's hot (6)

Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
Intro to Crystal Programming Language
Intro to Crystal Programming LanguageIntro to Crystal Programming Language
Intro to Crystal Programming Language
 
El viaje de Angular1 a Angular2
El viaje de Angular1 a Angular2El viaje de Angular1 a Angular2
El viaje de Angular1 a Angular2
 
Dart
DartDart
Dart
 
Case class scala
Case class scalaCase class scala
Case class scala
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 

Viewers also liked

Stairway to scala flyer
Stairway to scala flyerStairway to scala flyer
Stairway to scala flyerdickwall
 
Codemotion 2015 - Akka voló sobre el nido del future
Codemotion 2015 - Akka voló sobre el nido del futureCodemotion 2015 - Akka voló sobre el nido del future
Codemotion 2015 - Akka voló sobre el nido del futurescalerablog
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To ScalaPeter Maas
 
Scala jeff
Scala jeffScala jeff
Scala jeffjeff kit
 
Introduction to Asynchronous scala
Introduction to Asynchronous scalaIntroduction to Asynchronous scala
Introduction to Asynchronous scalaStratio
 
Spark summit2014 techtalk - testing spark
Spark summit2014 techtalk - testing sparkSpark summit2014 techtalk - testing spark
Spark summit2014 techtalk - testing sparkAnu Shetty
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applicationsKnoldus Inc.
 
Effective testing for spark programs Strata NY 2015
Effective testing for spark programs   Strata NY 2015Effective testing for spark programs   Strata NY 2015
Effective testing for spark programs Strata NY 2015Holden Karau
 

Viewers also liked (15)

Scala for dummies
Scala for dummiesScala for dummies
Scala for dummies
 
Stairway to scala flyer
Stairway to scala flyerStairway to scala flyer
Stairway to scala flyer
 
Codemotion 2015 - Akka voló sobre el nido del future
Codemotion 2015 - Akka voló sobre el nido del futureCodemotion 2015 - Akka voló sobre el nido del future
Codemotion 2015 - Akka voló sobre el nido del future
 
Scala@real life
Scala@real lifeScala@real life
Scala@real life
 
Codemotion 2014 Scala @real life
Codemotion 2014 Scala @real lifeCodemotion 2014 Scala @real life
Codemotion 2014 Scala @real life
 
Introducción a akka
Introducción a akkaIntroducción a akka
Introducción a akka
 
Scala @ Real Life Codemotion 2014
Scala @ Real Life Codemotion 2014Scala @ Real Life Codemotion 2014
Scala @ Real Life Codemotion 2014
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
Scala jeff
Scala jeffScala jeff
Scala jeff
 
Introduction to Asynchronous scala
Introduction to Asynchronous scalaIntroduction to Asynchronous scala
Introduction to Asynchronous scala
 
Spark summit2014 techtalk - testing spark
Spark summit2014 techtalk - testing sparkSpark summit2014 techtalk - testing spark
Spark summit2014 techtalk - testing spark
 
Unit testing of spark applications
Unit testing of spark applicationsUnit testing of spark applications
Unit testing of spark applications
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
 
Effective testing for spark programs Strata NY 2015
Effective testing for spark programs   Strata NY 2015Effective testing for spark programs   Strata NY 2015
Effective testing for spark programs Strata NY 2015
 

Similar to Scala Programming Madrid 2015

Codemotion akka voló sobre el nido del future
Codemotion   akka voló sobre el nido del futureCodemotion   akka voló sobre el nido del future
Codemotion akka voló sobre el nido del futureJavier Santos Paniego
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQLVMware Tanzu
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming LanguageHaim Michael
 
Laskar: High-Velocity GraphQL & Lambda-based Software Development Model
Laskar: High-Velocity GraphQL & Lambda-based Software Development ModelLaskar: High-Velocity GraphQL & Lambda-based Software Development Model
Laskar: High-Velocity GraphQL & Lambda-based Software Development ModelGarindra Prahandono
 
Porting R Models into Scala Spark
Porting R Models into Scala SparkPorting R Models into Scala Spark
Porting R Models into Scala Sparkcarl_pulley
 
Estructurar y mantener aplicaciones Rails sin morir en el intento
Estructurar y mantener aplicaciones Rails sin morir en el intentoEstructurar y mantener aplicaciones Rails sin morir en el intento
Estructurar y mantener aplicaciones Rails sin morir en el intentoMoisés Maciá
 
JDT embraces lambda expressions
JDT embraces lambda expressionsJDT embraces lambda expressions
JDT embraces lambda expressionsEclipse Day India
 
Anatomy of spark catalyst
Anatomy of spark catalystAnatomy of spark catalyst
Anatomy of spark catalystdatamantra
 
Introduction to Spark ML Pipelines Workshop
Introduction to Spark ML Pipelines WorkshopIntroduction to Spark ML Pipelines Workshop
Introduction to Spark ML Pipelines WorkshopHolden Karau
 
Modular GraphQL with Schema Stitching
Modular GraphQL with Schema StitchingModular GraphQL with Schema Stitching
Modular GraphQL with Schema StitchingSashko Stubailo
 
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion   akka persistence, cqrs%2 fes y otras siglas del montónCodemotion   akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion akka persistence, cqrs%2 fes y otras siglas del montónJavier Santos Paniego
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
Apache Jena Elephas and Friends
Apache Jena Elephas and FriendsApache Jena Elephas and Friends
Apache Jena Elephas and FriendsRob Vesse
 
Efficient HTTP applications on the JVM with Ratpack - JDD 2015
Efficient HTTP applications on the JVM with Ratpack - JDD 2015Efficient HTTP applications on the JVM with Ratpack - JDD 2015
Efficient HTTP applications on the JVM with Ratpack - JDD 2015Alvaro Sanchez-Mariscal
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScriptJorg Janke
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusBoldRadius Solutions
 

Similar to Scala Programming Madrid 2015 (20)

Introduction to spark
Introduction to sparkIntroduction to spark
Introduction to spark
 
Codemotion akka voló sobre el nido del future
Codemotion   akka voló sobre el nido del futureCodemotion   akka voló sobre el nido del future
Codemotion akka voló sobre el nido del future
 
Getting Started with Spring for GraphQL
Getting Started with Spring for GraphQLGetting Started with Spring for GraphQL
Getting Started with Spring for GraphQL
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
 
Laskar: High-Velocity GraphQL & Lambda-based Software Development Model
Laskar: High-Velocity GraphQL & Lambda-based Software Development ModelLaskar: High-Velocity GraphQL & Lambda-based Software Development Model
Laskar: High-Velocity GraphQL & Lambda-based Software Development Model
 
Porting R Models into Scala Spark
Porting R Models into Scala SparkPorting R Models into Scala Spark
Porting R Models into Scala Spark
 
Estructurar y mantener aplicaciones Rails sin morir en el intento
Estructurar y mantener aplicaciones Rails sin morir en el intentoEstructurar y mantener aplicaciones Rails sin morir en el intento
Estructurar y mantener aplicaciones Rails sin morir en el intento
 
Spark
SparkSpark
Spark
 
JDT embraces lambda expressions
JDT embraces lambda expressionsJDT embraces lambda expressions
JDT embraces lambda expressions
 
Anatomy of spark catalyst
Anatomy of spark catalystAnatomy of spark catalyst
Anatomy of spark catalyst
 
Introduction to Spark ML Pipelines Workshop
Introduction to Spark ML Pipelines WorkshopIntroduction to Spark ML Pipelines Workshop
Introduction to Spark ML Pipelines Workshop
 
Modular GraphQL with Schema Stitching
Modular GraphQL with Schema StitchingModular GraphQL with Schema Stitching
Modular GraphQL with Schema Stitching
 
Java SE 8 library design
Java SE 8 library designJava SE 8 library design
Java SE 8 library design
 
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion   akka persistence, cqrs%2 fes y otras siglas del montónCodemotion   akka persistence, cqrs%2 fes y otras siglas del montón
Codemotion akka persistence, cqrs%2 fes y otras siglas del montón
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Apache Jena Elephas and Friends
Apache Jena Elephas and FriendsApache Jena Elephas and Friends
Apache Jena Elephas and Friends
 
Scala Online Training.pdf
Scala Online Training.pdfScala Online Training.pdf
Scala Online Training.pdf
 
Efficient HTTP applications on the JVM with Ratpack - JDD 2015
Efficient HTTP applications on the JVM with Ratpack - JDD 2015Efficient HTTP applications on the JVM with Ratpack - JDD 2015
Efficient HTTP applications on the JVM with Ratpack - JDD 2015
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Scala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadiusScala Days Highlights | BoldRadius
Scala Days Highlights | BoldRadius
 

Recently uploaded

OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 

Recently uploaded (20)

OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 

Scala Programming Madrid 2015

  • 1. MADRID · MAR · 2015 Scala Programming @ Madrid Scala David Vallejo & Javier Santos
  • 2. MADRID · MAR · 2015 Scala Programming @ Madrid About us Javier Santos @jpaniego «Hay dos formas de programar sin errores; solo la tercera funciona» Alan J Perlis David Vallejo @dvnavarro «Una expresión regular es una expresión que no es del todo buena, pero tampoco del todo mala.» @borjamonserrano
  • 3. MADRID · MAR · 2015 Scala Programming @ Madrid What’s Scala? According Wikipedia: Scala (/ˈskɑːlə/ SKAH-lə)[6] is an object-functional[7] programming language for general software applications. Scala has full support for functional programming and a very strong static type system. This allows programs written in Scala to be very concise and thus smaller in size than other general-purpose programming languages. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java.[5]
  • 4. MADRID · MAR · 2015 Scala Programming @ Madrid What’s Scala? According to the official website:
  • 5. MADRID · MAR · 2015 Scala Programming @ Madrid What’s Scala? According to newbies:
  • 6. MADRID · MAR · 2015 Scala Programming @ Madrid What’s Scala? ● General purpose language that runs on the JVM. ● Martin Odersky ● Multiple Inheritance ● Multi-paradigm: functional & object-oriented ● Typesafe (2011) ● TIOBE (41st position)
  • 7. MADRID · MAR · 2015 Scala Programming @ Madrid Why so fashionable these days? ● Useful tools to build concurrent systems ○ More cores, more concurrency ○ Avoid side effects using functional programming and immutable values ○ Actor paradigm with the toolkit called Akka ● Awesome frameworks and tool-kits: Play Framework, Akka, Spark, Spray ... ● Others ○ Powerful mechanisms for embedding DSL like, for example, implicits ○ The best of functional world and the best of OO world ○ Elegant & concise
  • 8. MADRID · MAR · 2015 Scala Programming @ Madrid Who uses it?
  • 9. MADRID · MAR · 2015 Scala Programming @ Madrid Developer environment ● REPL (Read-eval-print loop) http://scala-lang.org/download/ ● SBT http://www.scala-sbt.org/ ● IDES: Eclipse http://scala-ide.org/download/sdk.html Intellij https://www.jetbrains.com/idea/features/scala.html NetBeans http://wiki.netbeans.org/Scala
  • 10. MADRID · MAR · 2015 Scala Programming @ Madrid Features
  • 11. MADRID · MAR · 2015 Scala Programming @ Madrid val vs var ● Type inference ● var: variables (mutable) ● val: values (immutable) ● lazy vals: Not evaluated until necessary
  • 12. MADRID · MAR · 2015 Scala Programming @ Madrid val vs var ● vals are always immutable? Stateful objects (mutable collections for example) (watch out with side effects)
  • 13. MADRID · MAR · 2015 Scala Programming @ Madrid Methods/functions ● Type inference ● Only braces means Unit ● No return necessary ● Variable args number (*)
  • 14. MADRID · MAR · 2015 Scala Programming @ Madrid What about class? ● A class may contain ○ attributes (var/val) ○ methods (def) ○ expressions that will be evaluated at instantiation time.
  • 15. MADRID · MAR · 2015 Scala Programming @ Madrid What about class? ● A simple class with no parameters
  • 16. MADRID · MAR · 2015 Scala Programming @ Madrid What about class? ● A simple class with parameters
  • 17. MADRID · MAR · 2015 Scala Programming @ Madrid What about class? ● A simple class with parameter accessors
  • 18. MADRID · MAR · 2015 Scala Programming @ Madrid What about abstract class? ● It cannot be instantiated, unless ...
  • 19. MADRID · MAR · 2015 Scala Programming @ Madrid What about case class? ● A case class provides: ○ parameter accessors ○ companion object with apply and unapply ○ extends from Serializable ○ copy method ● ...but it cannot be extended (We can handle that)
  • 20. MADRID · MAR · 2015 Scala Programming @ Madrid What about case class?
  • 21. MADRID · MAR · 2015 Scala Programming @ Madrid
  • 22. MADRID · MAR · 2015 Scala Programming @ Madrid Rich interfaces: trait ● Methods can be implemented. ● Multiple inheritance.
  • 23. MADRID · MAR · 2015 Scala Programming @ Madrid Inheritance: mixing in stuff... ● Linearization (Watch out the order)
  • 24. MADRID · MAR · 2015 Scala Programming @ Madrid What about nulls in Scala? ● Use option instead ● Two possible values: Some(t) and None
  • 25. MADRID · MAR · 2015 Scala Programming @ Madrid Options in Scala ● Besides it’s iterable! ● Nice functional methods like fold.
  • 26. MADRID · MAR · 2015 Scala Programming @ Madrid Generics ● For classes and traits
  • 27. MADRID · MAR · 2015 Scala Programming @ Madrid Generics ● For methods
  • 28. MADRID · MAR · 2015 Scala Programming @ Madrid Generics ● Variance: C[T] != C[+T] != C[-T]
  • 29. MADRID · MAR · 2015 Scala Programming @ Madrid Conditional statements: if
  • 30. MADRID · MAR · 2015 Scala Programming @ Madrid Conditional statements: match ● Similar to a Java switch...
  • 31. MADRID · MAR · 2015 Scala Programming @ Madrid Conditional statements: match ● ...except that it’s not only a switch :-) ● Pattern matching.
  • 32. MADRID · MAR · 2015 Scala Programming @ Madrid Conditional statements: match ● So it’s great, but be carefull with
  • 33. MADRID · MAR · 2015 Scala Programming @ Madrid Loop statements: while ● Not very commonly used (vars and so on…)
  • 34. MADRID · MAR · 2015 Scala Programming @ Madrid Loop statements: for ● for-comprehensions: syntactic sugar for
  • 35. MADRID · MAR · 2015 Scala Programming @ Madrid Loop statements: for ● Typical example: Is this purely functional?
  • 36. MADRID · MAR · 2015 Scala Programming @ Madrid Loops in Scala
  • 37. MADRID · MAR · 2015 Scala Programming @ Madrid Your new friend: fold ● Two signatures: foldLeft and foldRight (iterative vs. recursive) ● Same example:
  • 38. MADRID · MAR · 2015 Scala Programming @ Madrid Other common friends: map ● Convert each element to another (or same) type. ● Example:
  • 39. MADRID · MAR · 2015 Scala Programming @ Madrid Other common friends: flatMap ● Map each element to some monad-like type and flatten them ● Example:
  • 40. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Type alias ● Useful for specifying anonymous tuple types
  • 41. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Higher order functions ● Javascript ninjas gonna like…
  • 42. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Higher order functions
  • 43. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Higher order functions
  • 44. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Infix notation, semicolon inference... ● Allows writing readable code ● Specially useful for DSLs.
  • 45. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Infix notation, semicolon inference...
  • 46. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Implicits
  • 47. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Implicits ● Defined by scope (be careful with ambiguity) ● Specially difficult to trace: use only in very located places
  • 48. MADRID · MAR · 2015 Scala Programming @ Madrid More cool stuff: Self types ● Used for disambiguating with duplicated val/function names
  • 49. MADRID · MAR · 2015 Scala Programming @ Madrid Conclusions ● Steep learning curve ● It's hard to know which is the best way to do something ● Language expanding. More and more Scala enthusiasts. ● Mix the functional world and the OO world :)
  • 50. MADRID · MAR · 2015 Scala Programming @ Madrid
  • 51. MADRID · MAR · 2015 Scala Programming @ Madrid Scala David Vallejo & Javier Santos
  • 52. MADRID · MAR · 2015 Scala Programming @ Madrid scalerablog.wordpress.com @scalerablog