Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Scala
Functional programming for the imperative mind
Scala
Functional programming for the imperative mind

                                    ‘of the nature of or
                                        expressing a
                                         command;
                                       commanding.’
                                        - imperative.
(n.d.).

                                          Dictionary.com
Scala
                      ‘imperative
Functional   programmingisfor the            imperative mind
                  programming a
               programming paradigm
                    that describes
               computation in terms of
               statements that change
                   a program state.’
                  -
Imperative
programming
                       Wikipedia.com
Outline
• Introduction
• Functional programming
• Scala features
• Java to Scala in three steps
• Scala community
• Wrap up
Roots
• Created by Martin Odersky
• Supported by EPFL Switzerland
What is Scala?
A programming language ...

• Runs on JVM  (and .Net)


• Statically typed
• Object Oriented
• Functional
• From scripting to enterprise apps
Scalable language
• Scalable language constructs:
  • Composition ‘in the small’
  • Composition ‘in the large’
• Java interoperability
• Performance on par with Java
Scalable language
• Scalable language constructs:
  • Composition ‘in the small’
  • Composition ‘in the large’
• Java interoperability
• Performance on par with Java



     Fuses functional and object oriented paradigms
What is



Functional
           Programming
Functional programming

• Focus on functions, not state         fx=x+1

• Functions are values                      vs.
• Recursion, not loops                   x=x+1

• Immutability (‘referential transparency’)
• Schools of thought:
    pure and impure (‘pragmatic’)
Functional programming

• Focus on functions, not state         fx=x+1

• Functions are values                      vs.
• Recursion, not loops                   x=x+1

• Immutability (‘referential transparency’)
• Schools of thought:
    pure and impure (‘pragmatic’)
Functional programming

• Focus on functions, not state
• Functions are values                 f g x = g(x)

• Recursion, not loops
• Immutability (‘referential transparency’)
• Schools of thought:
     pure and impure (‘pragmatic’)
Functional programming

• Focus on functions, not state          f0=0
                                         fx=

• Functions are values
                                          f (x - 1)
                                              vs.
• Recursion, not loops                  for(i=x; i>0
                                           ; i--) {

• Immutability (‘referential transparency’)x--; }


• Schools of thought:
     pure and impure (‘pragmatic’)
Functional programming

• Focus on functions, not state
• Functions are values
• Recursion, not loops
• Immutability (‘referential transparency’)
• Schools of thought:
     pure and impure (‘pragmatic’)
Functional programming
    Why should I care about FP?
•   Concurrency: FP ‘killer app’
•   Higher order functions: expressiveness boost
•   Type-system: when present, often superior
•   It is coming to a language near you
    (C#, Java 8?)
FP in Scala

• First-class functions: functions are objects
  with pleasing syntax
• Immutability
• Algebraic data-types and pattern matching
• Parametric polymorphism (e.g. generics)
What are



  Scala’s
      Features
Scala is like Java...
(Generic) classes:                         class Foo[T], or:
                                           class Foo[+T]
public class Foo<T>

Methods:
                                           def m(s : String) : Unit = ..
public void m(String s) {..}

Bean properties: private Foo foo;          Real properties:
getFoo() {..}, setFoo(..) {..}             var foo: Foo

                                           Fully interoperable with existing Java
Mature, large amount of proven libraries
                                           code

Class/Interface distinction, single        Abstract classes, traits (restricted
inheritance.                               multiple inheritance)
Pure object orientation
No primitive types:
Pure object orientation
No primitive types:
Pure object orientation
Every operation is a method call:
              1+3           1.+(3)
Pure object orientation
 Every operation is a method call:
                1+3          1.+(3)
Console.println(“hi”)       Console println “hi”
Pure object orientation
 Every operation is a method call:
                1+3           1.+(3)
Console.println(“hi”)        Console println “hi”

         Since operators are methods,
         operator overloading is trivial.
Pure object orientation
 Every operation is a method call:
                1+3          1.+(3)
Console.println(“hi”)       Console println “hi”
Pure object orientation
 Every operation is a method call:
                1+3          1.+(3)
Console.println(“hi”)       Console println “hi”
Pure object orientation
No static members, but singleton objects:
Type inference
• Types may be omitted in declarations




• Does not mean there is no type!
• Inference is local only
• Var/val: mutable vs. immutable
Type inference
Everything is an expression
Everything is an expression
Everything is an expression
Everything is an expression
Functional objects
• Functions are first-class values
• Function literals:
Functional objects
• Functions are first-class values
• Function literals:
    (x: Int) => x * 2
Functional objects
• Functions are first-class values
• Function literals:
    (x: Int) => x * 2
    val double = (x: Int) => x * 2
Functional objects
• Functions are first-class values
• Function literals:
    (x: Int) => x * 2
    val double = (x: Int) => x * 2
    double(2) == 4

        What is the type of double?
Functional types
val double = (x: Int) => x * 2
        has type
(Int) => Int
Functional types
val double = (x: Int) => x * 2
        has type
(Int) => Int            Function1[Int,Int]
Passing functions
Since functions are values, we can
        pass them around:
Passing functions
But we can do this with anonymous classes...
Passing functions
But we can do this with anonymous classes...
Passing functions
But we can do this with anonymous classes...
Passing functions
  But we can do this with anonymous classes...
  Well, sort of... but:
• You need explicit interfaces (no function types)
• Verbose
• Doesn’t scale (syntactically and semantically)
• No true closures:
Passing functions
  But we can do this with anonymous classes...
  Well, sort of... but:
• You need explicit interfaces (no function types)
• Verbose
• Doesn’t scale (syntactically and semantically)
• No true closures:
Traits
• Compare trait with abstract class
• No interfaces, but: completely abstract traits
• Can mixin multiple traits, statically and
  dynamically
Traits as rich interfaces
Java interfaces have two consumers with
conflicting interests:
 1) Implementors
 2) Users
Traits as rich interfaces
Java interfaces have two consumers with
conflicting interests:
 1) Implementors
 2) Users
Traits as stackable
         modifications
• Situation: IntQueue interface (abstract trait),
  
 IntQueueImpl implementation
• We want to add logging and filtering to any
  IntQueue implementation
Traits as stackable
         modifications
• Situation: IntQueue interface (abstract trait),
  
 IntQueueImpl implementation
• We want to add logging and filtering to any
  IntQueue implementation
Traits as stackable
         modifications
• Situation: IntQueue interface (abstract trait),
  
 IntQueueImpl implementation
• We want to add logging and filtering to any
  IntQueue implementation
Pattern matching
Pattern matching
Pattern matching




    Yes, it prints 9
Pattern matching
• No more instanceof/typecasts
• No more visitor pattern
Pattern matching
• No more instanceof/typecasts
• No more visitor pattern
       No more NullPointerException:
Pattern matching & XML
• Scala has XML literals, can be matched
• Other literals can be matched as well
Language feature or




            Library
                      Support
Actors
• Message-based concurrency
• Actors exchange immutable messages
• Extract them by pattern matching
Actors
• Message-based concurrency
• Actors exchange immutable messages
• Extract them by pattern matching



 Looks like language feature, but is a library
Other library features
• Enums
• Map ‘syntax’
• Events
• Using ‘keyword’ (e.g. Java 7 ‘automatic
  resource management.’)
• Virtually all other Project Coin proposals
Other library features
• Enums
• Map ‘syntax’
• Events
• Using ‘keyword’ (e.g. Java 7 ‘automatic
  resource management.’)
• Virtually all other Project Coin proposals
Other library features
• Enums
• Map ‘syntax’
• Events
• Using ‘keyword’ (e.g. Java 7 ‘automatic
  resource management.’)
• Virtually all other Project Coin proposals
Other library features
• Enums
• Map ‘syntax’
• Events
• Using ‘keyword’ (e.g. Java 7 ‘automatic
  resource management.’)
• Virtually all other Project Coin proposals
     Lesson: choose language core wisely,
                        all else will follow...
Lift webframework
In own words:
   ✓Seaside's highly granular sessions and security
   ✓Rails fast flash-to-bang
   ✓Django's quot;more than just CRUD is includedquot;
   ✓Wicket's designer-friendly templating style
• Heavy use of actors for async features
• Integrated O/R mapping (surprisingly little
  boilerplate code)
From Java to Scala


            In
       Three steps
Requirements
•   Person entity with age
    property

•   Method to separate
    minors and adults

•   Input: List[Person]

•   Output: list of minors,
    list of adults

•   One pass over input
Requirements
•   Person entity with age
    property

•   Method to separate
    minors and adults

•   Input: List[Person]

•   Output: list of minors,
    list of adults

•   One pass over input
What happens in the



    Scala
       Community
Scala progression

• Current version: 2.7.4
• Version 2.8 beta coming up:
 •   Package objects

 •   Named and default parameters

 •   Many library improvements
Tool support
•   Major IDEs (Eclipse,
    IntelliJ, NetBeans)
    supported

•   Maven support

•   Scaladoc

•   SBaz package manager
Wrapping up with




     Concluding
                   Remarks
Scala hitting mainstream?
Reports of first switchers
   Twitter, SAP, LinkedIn, Sony Pictures
Scala hitting mainstream?
Reports of first switchers
   Twitter, SAP, LinkedIn, Sony Pictures
April 2009: top-30 of TIOBE index
Scala hitting mainstream?
Reports of first switchers
   Twitter, SAP, LinkedIn, Sony Pictures
April 2009: top-30 of TIOBE index
Lots of books appearing
Scala hitting mainstream?

“If I were to pick a language today
other than Java, it would be Scala”




                  James Gosling,
                     ‘Father of Java’
Scala hitting mainstream?
   “If Java programmers want to use
   features that aren't present in the
language, I think they're probably best
off using another language that targets
  the JVM, such a Scala and Groovy.”




                    Joshua Bloch
                 Author of ‘Effective Java’
Pro’s and cons
                          • Complexity
• Java interoperability
                          • Java -> Scala
• Hides accidental
  complexity                harder than
                            Scala -> Java
• Expressiveness
                          • Type-system may
• Uniform, extensible       be intimidating
  language
Conclusion
•   Scala feels like ‘cleaned up Java on stereoids’

•   Small core (takes some time to see it as such)
    provides broad options

•   Type inference brings ‘dynamic language’ feel

•   Adoptation growing because of:

    •   Java interoperability

    •   Growing discontent with Java
Conclusion
•   Scala feels like ‘cleaned up Java on stereoids’

•   Small core (takes some time to see it as such)
    provides broad options

•   Type inference brings ‘dynamic language’ feel

•   Adoptation growing because of:

    •   Java interoperability

    •   Growing discontent with Java

    Scala provides deep features, but at the
      same time helps getting things done.
More
  information
 http://www.scala-lang.org

     http://liftweb.net

Article Java Magazine 1/2009
Questions?

More Related Content

What's hot

GraalVM
GraalVMGraalVM
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
Mario Fusco
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
Mohammad Hossein Rimaz
 
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...
confluent
 
Core Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug HuntCore Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug Hunt
CodeOps Technologies LLP
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
Matthias Noback
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
Simone Bordet
 
Java 11 to 17 : What's new !?
Java 11 to 17 : What's new !?Java 11 to 17 : What's new !?
Java 11 to 17 : What's new !?
Jérôme Tamborini
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
CodeOps Technologies LLP
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
Venkata Naga Ravi
 
Stream processing with Apache Flink (Timo Walther - Ververica)
Stream processing with Apache Flink (Timo Walther - Ververica)Stream processing with Apache Flink (Timo Walther - Ververica)
Stream processing with Apache Flink (Timo Walther - Ververica)
KafkaZone
 
Core java
Core java Core java
Core java
Shubham singh
 
Scylla Summit 2022: New AWS Instances Perfect for ScyllaDB
Scylla Summit 2022: New AWS Instances Perfect for ScyllaDBScylla Summit 2022: New AWS Instances Perfect for ScyllaDB
Scylla Summit 2022: New AWS Instances Perfect for ScyllaDB
ScyllaDB
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
Izzet Mustafaiev
 
Support distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcastSupport distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcast
ENSET, Université Hassan II Casablanca
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Rahul Jain
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
Niyitegekabilly
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
NexThoughts Technologies
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
React Class Components vs Functional Components: Which is Better?
React Class Components vs Functional Components: Which is Better?React Class Components vs Functional Components: Which is Better?
React Class Components vs Functional Components: Which is Better?
Fibonalabs
 

What's hot (20)

GraalVM
GraalVMGraalVM
GraalVM
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...
Apache Kafka vs. Integration Middleware (MQ, ETL, ESB) - Friends, Enemies or ...
 
Core Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug HuntCore Java - Quiz Questions - Bug Hunt
Core Java - Quiz Questions - Bug Hunt
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
Java 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgradeJava 9/10/11 - What's new and why you should upgrade
Java 9/10/11 - What's new and why you should upgrade
 
Java 11 to 17 : What's new !?
Java 11 to 17 : What's new !?Java 11 to 17 : What's new !?
Java 11 to 17 : What's new !?
 
Java Concurrency by Example
Java Concurrency by ExampleJava Concurrency by Example
Java Concurrency by Example
 
Java 8 Lambda and Streams
Java 8 Lambda and StreamsJava 8 Lambda and Streams
Java 8 Lambda and Streams
 
Stream processing with Apache Flink (Timo Walther - Ververica)
Stream processing with Apache Flink (Timo Walther - Ververica)Stream processing with Apache Flink (Timo Walther - Ververica)
Stream processing with Apache Flink (Timo Walther - Ververica)
 
Core java
Core java Core java
Core java
 
Scylla Summit 2022: New AWS Instances Perfect for ScyllaDB
Scylla Summit 2022: New AWS Instances Perfect for ScyllaDBScylla Summit 2022: New AWS Instances Perfect for ScyllaDB
Scylla Summit 2022: New AWS Instances Perfect for ScyllaDB
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Support distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcastSupport distributed computing and caching avec hazelcast
Support distributed computing and caching avec hazelcast
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
React Class Components vs Functional Components: Which is Better?
React Class Components vs Functional Components: Which is Better?React Class Components vs Functional Components: Which is Better?
React Class Components vs Functional Components: Which is Better?
 

Viewers also liked

Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
pramode_ce
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
Shahriar Hyder
 
Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)
stasimus
 
Developers Summit 2015 - Scala Monad
Developers Summit 2015 - Scala MonadDevelopers Summit 2015 - Scala Monad
Developers Summit 2015 - Scala Monad
Sangwon Han
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
Patrick Nicolas
 
Java 8 - functional features
Java 8 - functional featuresJava 8 - functional features
Java 8 - functional features
Rafal Rybacki
 
Elements of functional programming
Elements of functional programmingElements of functional programming
Elements of functional programming
Sajjad Ali Pulikkanat
 
Object oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programmingObject oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programming
kukurmutta
 
Why functional why scala
Why functional  why scala Why functional  why scala
Why functional why scala
Neville Li
 
Scala the language matters
Scala the language mattersScala the language matters
Scala the language matters
Xiaojun REN
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
stasimus
 
Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
samthemonad
 
Zaharia spark-scala-days-2012
Zaharia spark-scala-days-2012Zaharia spark-scala-days-2012
Zaharia spark-scala-days-2012
Skills Matter Talks
 
Introduction to scala for a c programmer
Introduction to scala for a c programmerIntroduction to scala for a c programmer
Introduction to scala for a c programmer
Girish Kumar A L
 
Jump Start into Apache Spark (Seattle Spark Meetup)
Jump Start into Apache Spark (Seattle Spark Meetup)Jump Start into Apache Spark (Seattle Spark Meetup)
Jump Start into Apache Spark (Seattle Spark Meetup)
Denny Lee
 
Apache hive
Apache hiveApache hive
Apache hive
pradipbajpai68
 
Thinking functional-in-scala
Thinking functional-in-scalaThinking functional-in-scala
Thinking functional-in-scala
Knoldus Inc.
 
Introduction to Option monad in Scala
Introduction to Option monad in ScalaIntroduction to Option monad in Scala
Introduction to Option monad in Scala
Jan Krag
 
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Databricks
 
Python to scala
Python to scalaPython to scala
Python to scala
kao kuo-tung
 

Viewers also liked (20)

Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Functional Programming Fundamentals
Functional Programming FundamentalsFunctional Programming Fundamentals
Functional Programming Fundamentals
 
Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)Introduction to Monads in Scala (1)
Introduction to Monads in Scala (1)
 
Developers Summit 2015 - Scala Monad
Developers Summit 2015 - Scala MonadDevelopers Summit 2015 - Scala Monad
Developers Summit 2015 - Scala Monad
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 
Java 8 - functional features
Java 8 - functional featuresJava 8 - functional features
Java 8 - functional features
 
Elements of functional programming
Elements of functional programmingElements of functional programming
Elements of functional programming
 
Object oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programmingObject oriented-programming-vs-procedural-programming
Object oriented-programming-vs-procedural-programming
 
Why functional why scala
Why functional  why scala Why functional  why scala
Why functional why scala
 
Scala the language matters
Scala the language mattersScala the language matters
Scala the language matters
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
 
Zaharia spark-scala-days-2012
Zaharia spark-scala-days-2012Zaharia spark-scala-days-2012
Zaharia spark-scala-days-2012
 
Introduction to scala for a c programmer
Introduction to scala for a c programmerIntroduction to scala for a c programmer
Introduction to scala for a c programmer
 
Jump Start into Apache Spark (Seattle Spark Meetup)
Jump Start into Apache Spark (Seattle Spark Meetup)Jump Start into Apache Spark (Seattle Spark Meetup)
Jump Start into Apache Spark (Seattle Spark Meetup)
 
Apache hive
Apache hiveApache hive
Apache hive
 
Thinking functional-in-scala
Thinking functional-in-scalaThinking functional-in-scala
Thinking functional-in-scala
 
Introduction to Option monad in Scala
Introduction to Option monad in ScalaIntroduction to Option monad in Scala
Introduction to Option monad in Scala
 
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
Performance Optimization Case Study: Shattering Hadoop's Sort Record with Spa...
 
Python to scala
Python to scalaPython to scala
Python to scala
 

Similar to Scala: functional programming for the imperative mind

javascript teach
javascript teachjavascript teach
javascript teach
guest3732fa
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
guest3732fa
 
LISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love ParanthesesLISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love Parantheses
Dominic Graefen
 
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Innovecs
 
Introductory func prog
Introductory func progIntroductory func prog
Introductory func prog
Oleksandr Khomenko
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
Talha Ocakçı
 
Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)
Omar Abdelhafith
 
Introductiontoprogramminginscala
IntroductiontoprogramminginscalaIntroductiontoprogramminginscala
Introductiontoprogramminginscala
Amuhinda Hungai
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.
Brian Hsu
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
kankemwa Ishaku
 
Scala ntnu
Scala ntnuScala ntnu
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
Miles Sabin
 
Introduction to Erlang Programming Language
Introduction to Erlang Programming LanguageIntroduction to Erlang Programming Language
Introduction to Erlang Programming Language
Yasas Gunarathne
 
Java 101
Java 101Java 101
Java 101
Manuela Grindei
 
javascript
javascript javascript
javascript
Kaya Ota
 
Java
JavaJava

Similar to Scala: functional programming for the imperative mind (20)

javascript teach
javascript teachjavascript teach
javascript teach
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
 
LISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love ParanthesesLISP: How I Learned To Stop Worrying And Love Parantheses
LISP: How I Learned To Stop Worrying And Love Parantheses
 
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
Introduction Functional Programming - Tech Hangout #11 - 2013.01.16
 
Introductory func prog
Introductory func progIntroductory func prog
Introductory func prog
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)Introduction to functional programming (In Arabic)
Introduction to functional programming (In Arabic)
 
Introductiontoprogramminginscala
IntroductiontoprogramminginscalaIntroductiontoprogramminginscala
Introductiontoprogramminginscala
 
Programming Android Application in Scala.
Programming Android Application in Scala.Programming Android Application in Scala.
Programming Android Application in Scala.
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
 
Introduction to Erlang Programming Language
Introduction to Erlang Programming LanguageIntroduction to Erlang Programming Language
Introduction to Erlang Programming Language
 
Java 101
Java 101Java 101
Java 101
 
javascript
javascript javascript
javascript
 
Java
JavaJava
Java
 

More from Sander Mak (@Sander_Mak)

Scalable Application Development @ Picnic
Scalable Application Development @ PicnicScalable Application Development @ Picnic
Scalable Application Development @ Picnic
Sander Mak (@Sander_Mak)
 
Coding Your Way to Java 13
Coding Your Way to Java 13Coding Your Way to Java 13
Coding Your Way to Java 13
Sander Mak (@Sander_Mak)
 
Coding Your Way to Java 12
Coding Your Way to Java 12Coding Your Way to Java 12
Coding Your Way to Java 12
Sander Mak (@Sander_Mak)
 
Java Modularity: the Year After
Java Modularity: the Year AfterJava Modularity: the Year After
Java Modularity: the Year After
Sander Mak (@Sander_Mak)
 
Desiging for Modularity with Java 9
Desiging for Modularity with Java 9Desiging for Modularity with Java 9
Desiging for Modularity with Java 9
Sander Mak (@Sander_Mak)
 
Modules or microservices?
Modules or microservices?Modules or microservices?
Modules or microservices?
Sander Mak (@Sander_Mak)
 
Migrating to Java 9 Modules
Migrating to Java 9 ModulesMigrating to Java 9 Modules
Migrating to Java 9 Modules
Sander Mak (@Sander_Mak)
 
Java 9 Modularity in Action
Java 9 Modularity in ActionJava 9 Modularity in Action
Java 9 Modularity in Action
Sander Mak (@Sander_Mak)
 
Java modularity: life after Java 9
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9
Sander Mak (@Sander_Mak)
 
Provisioning the IoT
Provisioning the IoTProvisioning the IoT
Provisioning the IoT
Sander Mak (@Sander_Mak)
 
Event-sourced architectures with Akka
Event-sourced architectures with AkkaEvent-sourced architectures with Akka
Event-sourced architectures with Akka
Sander Mak (@Sander_Mak)
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
Sander Mak (@Sander_Mak)
 
The Ultimate Dependency Manager Shootout (QCon NY 2014)
The Ultimate Dependency Manager Shootout (QCon NY 2014)The Ultimate Dependency Manager Shootout (QCon NY 2014)
The Ultimate Dependency Manager Shootout (QCon NY 2014)
Sander Mak (@Sander_Mak)
 
Modular JavaScript
Modular JavaScriptModular JavaScript
Modular JavaScript
Sander Mak (@Sander_Mak)
 
Modularity in the Cloud
Modularity in the CloudModularity in the Cloud
Modularity in the Cloud
Sander Mak (@Sander_Mak)
 
Cross-Build Injection attacks: how safe is your Java build?
Cross-Build Injection attacks: how safe is your Java build?Cross-Build Injection attacks: how safe is your Java build?
Cross-Build Injection attacks: how safe is your Java build?
Sander Mak (@Sander_Mak)
 
Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)
Sander Mak (@Sander_Mak)
 
Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)
Sander Mak (@Sander_Mak)
 
Akka (BeJUG)
Akka (BeJUG)Akka (BeJUG)
Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)
Sander Mak (@Sander_Mak)
 

More from Sander Mak (@Sander_Mak) (20)

Scalable Application Development @ Picnic
Scalable Application Development @ PicnicScalable Application Development @ Picnic
Scalable Application Development @ Picnic
 
Coding Your Way to Java 13
Coding Your Way to Java 13Coding Your Way to Java 13
Coding Your Way to Java 13
 
Coding Your Way to Java 12
Coding Your Way to Java 12Coding Your Way to Java 12
Coding Your Way to Java 12
 
Java Modularity: the Year After
Java Modularity: the Year AfterJava Modularity: the Year After
Java Modularity: the Year After
 
Desiging for Modularity with Java 9
Desiging for Modularity with Java 9Desiging for Modularity with Java 9
Desiging for Modularity with Java 9
 
Modules or microservices?
Modules or microservices?Modules or microservices?
Modules or microservices?
 
Migrating to Java 9 Modules
Migrating to Java 9 ModulesMigrating to Java 9 Modules
Migrating to Java 9 Modules
 
Java 9 Modularity in Action
Java 9 Modularity in ActionJava 9 Modularity in Action
Java 9 Modularity in Action
 
Java modularity: life after Java 9
Java modularity: life after Java 9Java modularity: life after Java 9
Java modularity: life after Java 9
 
Provisioning the IoT
Provisioning the IoTProvisioning the IoT
Provisioning the IoT
 
Event-sourced architectures with Akka
Event-sourced architectures with AkkaEvent-sourced architectures with Akka
Event-sourced architectures with Akka
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
The Ultimate Dependency Manager Shootout (QCon NY 2014)
The Ultimate Dependency Manager Shootout (QCon NY 2014)The Ultimate Dependency Manager Shootout (QCon NY 2014)
The Ultimate Dependency Manager Shootout (QCon NY 2014)
 
Modular JavaScript
Modular JavaScriptModular JavaScript
Modular JavaScript
 
Modularity in the Cloud
Modularity in the CloudModularity in the Cloud
Modularity in the Cloud
 
Cross-Build Injection attacks: how safe is your Java build?
Cross-Build Injection attacks: how safe is your Java build?Cross-Build Injection attacks: how safe is your Java build?
Cross-Build Injection attacks: how safe is your Java build?
 
Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)Scala & Lift (JEEConf 2012)
Scala & Lift (JEEConf 2012)
 
Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)Hibernate Performance Tuning (JEEConf 2012)
Hibernate Performance Tuning (JEEConf 2012)
 
Akka (BeJUG)
Akka (BeJUG)Akka (BeJUG)
Akka (BeJUG)
 
Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)Fork Join (BeJUG 2012)
Fork Join (BeJUG 2012)
 

Recently uploaded

INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
jackson110191
 
Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
Vijayananda Mohire
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
BookNet Canada
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
apoorva2579
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
Aurora Consulting
 
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
amitchopra0215
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
SATYENDRA100
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
Stephanie Beckett
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
FellyciaHikmahwarani
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Erasmo Purificato
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
Yevgen Sysoyev
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Chris Swan
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Earley Information Science
 
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
uuuot
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
Matthew Sinclair
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
Enterprise Wired
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024
The Digital Insurer
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
UiPathCommunity
 

Recently uploaded (20)

INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfINDIAN AIR FORCE FIGHTER PLANES LIST.pdf
INDIAN AIR FORCE FIGHTER PLANES LIST.pdf
 
Quantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLMQuantum Communications Q&A with Gemini LLM
Quantum Communications Q&A with Gemini LLM
 
Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...Transcript: Details of description part II: Describing images in practice - T...
Transcript: Details of description part II: Describing images in practice - T...
 
AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)AC Atlassian Coimbatore Session Slides( 22/06/2024)
AC Atlassian Coimbatore Session Slides( 22/06/2024)
 
Quality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of TimeQuality Patents: Patents That Stand the Test of Time
Quality Patents: Patents That Stand the Test of Time
 
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
@Call @Girls Pune 0000000000 Riya Khan Beautiful Girl any Time
 
5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx5G bootcamp Sep 2020 (NPI initiative).pptx
5G bootcamp Sep 2020 (NPI initiative).pptx
 
What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024What’s New in Teams Calling, Meetings and Devices May 2024
What’s New in Teams Calling, Meetings and Devices May 2024
 
Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1Why do You Have to Redesign?_Redesign Challenge Day 1
Why do You Have to Redesign?_Redesign Challenge Day 1
 
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 
DealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 editionDealBook of Ukraine: 2024 edition
DealBook of Ukraine: 2024 edition
 
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...
 
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design ApproachesKnowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
Knowledge and Prompt Engineering Part 2 Focus on Prompt Design Approaches
 
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
一比一原版(msvu毕业证书)圣文森山大学毕业证如何办理
 
20240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 202420240704 QFM023 Engineering Leadership Reading List June 2024
20240704 QFM023 Engineering Leadership Reading List June 2024
 
7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf7 Most Powerful Solar Storms in the History of Earth.pdf
7 Most Powerful Solar Storms in the History of Earth.pdf
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024K2G - Insurtech Innovation EMEA Award 2024
K2G - Insurtech Innovation EMEA Award 2024
 
UiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs ConferenceUiPath Community Day Kraków: Devs4Devs Conference
UiPath Community Day Kraków: Devs4Devs Conference
 

Scala: functional programming for the imperative mind

  • 1. Scala Functional programming for the imperative mind
  • 2. Scala Functional programming for the imperative mind ‘of the nature of or expressing a command; commanding.’ - imperative.
(n.d.).
 Dictionary.com
  • 3. Scala ‘imperative Functional programmingisfor the imperative mind programming a programming paradigm that describes computation in terms of statements that change a program state.’ -
Imperative
programming Wikipedia.com
  • 4. Outline • Introduction • Functional programming • Scala features • Java to Scala in three steps • Scala community • Wrap up
  • 5. Roots • Created by Martin Odersky • Supported by EPFL Switzerland
  • 6. What is Scala? A programming language ... • Runs on JVM (and .Net) • Statically typed • Object Oriented • Functional • From scripting to enterprise apps
  • 7. Scalable language • Scalable language constructs: • Composition ‘in the small’ • Composition ‘in the large’ • Java interoperability • Performance on par with Java
  • 8. Scalable language • Scalable language constructs: • Composition ‘in the small’ • Composition ‘in the large’ • Java interoperability • Performance on par with Java Fuses functional and object oriented paradigms
  • 9. What is Functional Programming
  • 10. Functional programming • Focus on functions, not state fx=x+1 • Functions are values vs. • Recursion, not loops x=x+1 • Immutability (‘referential transparency’) • Schools of thought: pure and impure (‘pragmatic’)
  • 11. Functional programming • Focus on functions, not state fx=x+1 • Functions are values vs. • Recursion, not loops x=x+1 • Immutability (‘referential transparency’) • Schools of thought: pure and impure (‘pragmatic’)
  • 12. Functional programming • Focus on functions, not state • Functions are values f g x = g(x) • Recursion, not loops • Immutability (‘referential transparency’) • Schools of thought: pure and impure (‘pragmatic’)
  • 13. Functional programming • Focus on functions, not state f0=0 fx= • Functions are values f (x - 1) vs. • Recursion, not loops for(i=x; i>0 ; i--) { • Immutability (‘referential transparency’)x--; } • Schools of thought: pure and impure (‘pragmatic’)
  • 14. Functional programming • Focus on functions, not state • Functions are values • Recursion, not loops • Immutability (‘referential transparency’) • Schools of thought: pure and impure (‘pragmatic’)
  • 15. Functional programming Why should I care about FP? • Concurrency: FP ‘killer app’ • Higher order functions: expressiveness boost • Type-system: when present, often superior • It is coming to a language near you (C#, Java 8?)
  • 16. FP in Scala • First-class functions: functions are objects with pleasing syntax • Immutability • Algebraic data-types and pattern matching • Parametric polymorphism (e.g. generics)
  • 17. What are Scala’s Features
  • 18. Scala is like Java... (Generic) classes: class Foo[T], or: class Foo[+T] public class Foo<T> Methods: def m(s : String) : Unit = .. public void m(String s) {..} Bean properties: private Foo foo; Real properties: getFoo() {..}, setFoo(..) {..} var foo: Foo Fully interoperable with existing Java Mature, large amount of proven libraries code Class/Interface distinction, single Abstract classes, traits (restricted inheritance. multiple inheritance)
  • 19. Pure object orientation No primitive types:
  • 20. Pure object orientation No primitive types:
  • 21. Pure object orientation Every operation is a method call: 1+3 1.+(3)
  • 22. Pure object orientation Every operation is a method call: 1+3 1.+(3) Console.println(“hi”) Console println “hi”
  • 23. Pure object orientation Every operation is a method call: 1+3 1.+(3) Console.println(“hi”) Console println “hi” Since operators are methods, operator overloading is trivial.
  • 24. Pure object orientation Every operation is a method call: 1+3 1.+(3) Console.println(“hi”) Console println “hi”
  • 25. Pure object orientation Every operation is a method call: 1+3 1.+(3) Console.println(“hi”) Console println “hi”
  • 26. Pure object orientation No static members, but singleton objects:
  • 27. Type inference • Types may be omitted in declarations • Does not mean there is no type! • Inference is local only • Var/val: mutable vs. immutable
  • 29. Everything is an expression
  • 30. Everything is an expression
  • 31. Everything is an expression
  • 32. Everything is an expression
  • 33. Functional objects • Functions are first-class values • Function literals:
  • 34. Functional objects • Functions are first-class values • Function literals: (x: Int) => x * 2
  • 35. Functional objects • Functions are first-class values • Function literals: (x: Int) => x * 2 val double = (x: Int) => x * 2
  • 36. Functional objects • Functions are first-class values • Function literals: (x: Int) => x * 2 val double = (x: Int) => x * 2 double(2) == 4 What is the type of double?
  • 37. Functional types val double = (x: Int) => x * 2 has type (Int) => Int
  • 38. Functional types val double = (x: Int) => x * 2 has type (Int) => Int Function1[Int,Int]
  • 39. Passing functions Since functions are values, we can pass them around:
  • 40. Passing functions But we can do this with anonymous classes...
  • 41. Passing functions But we can do this with anonymous classes...
  • 42. Passing functions But we can do this with anonymous classes...
  • 43. Passing functions But we can do this with anonymous classes... Well, sort of... but: • You need explicit interfaces (no function types) • Verbose • Doesn’t scale (syntactically and semantically) • No true closures:
  • 44. Passing functions But we can do this with anonymous classes... Well, sort of... but: • You need explicit interfaces (no function types) • Verbose • Doesn’t scale (syntactically and semantically) • No true closures:
  • 45. Traits • Compare trait with abstract class • No interfaces, but: completely abstract traits • Can mixin multiple traits, statically and dynamically
  • 46. Traits as rich interfaces Java interfaces have two consumers with conflicting interests: 1) Implementors 2) Users
  • 47. Traits as rich interfaces Java interfaces have two consumers with conflicting interests: 1) Implementors 2) Users
  • 48. Traits as stackable modifications • Situation: IntQueue interface (abstract trait), IntQueueImpl implementation • We want to add logging and filtering to any IntQueue implementation
  • 49. Traits as stackable modifications • Situation: IntQueue interface (abstract trait), IntQueueImpl implementation • We want to add logging and filtering to any IntQueue implementation
  • 50. Traits as stackable modifications • Situation: IntQueue interface (abstract trait), IntQueueImpl implementation • We want to add logging and filtering to any IntQueue implementation
  • 53. Pattern matching Yes, it prints 9
  • 54. Pattern matching • No more instanceof/typecasts • No more visitor pattern
  • 55. Pattern matching • No more instanceof/typecasts • No more visitor pattern No more NullPointerException:
  • 56. Pattern matching & XML • Scala has XML literals, can be matched • Other literals can be matched as well
  • 57. Language feature or Library Support
  • 58. Actors • Message-based concurrency • Actors exchange immutable messages • Extract them by pattern matching
  • 59. Actors • Message-based concurrency • Actors exchange immutable messages • Extract them by pattern matching Looks like language feature, but is a library
  • 60. Other library features • Enums • Map ‘syntax’ • Events • Using ‘keyword’ (e.g. Java 7 ‘automatic resource management.’) • Virtually all other Project Coin proposals
  • 61. Other library features • Enums • Map ‘syntax’ • Events • Using ‘keyword’ (e.g. Java 7 ‘automatic resource management.’) • Virtually all other Project Coin proposals
  • 62. Other library features • Enums • Map ‘syntax’ • Events • Using ‘keyword’ (e.g. Java 7 ‘automatic resource management.’) • Virtually all other Project Coin proposals
  • 63. Other library features • Enums • Map ‘syntax’ • Events • Using ‘keyword’ (e.g. Java 7 ‘automatic resource management.’) • Virtually all other Project Coin proposals Lesson: choose language core wisely, all else will follow...
  • 64. Lift webframework In own words: ✓Seaside's highly granular sessions and security ✓Rails fast flash-to-bang ✓Django's quot;more than just CRUD is includedquot; ✓Wicket's designer-friendly templating style • Heavy use of actors for async features • Integrated O/R mapping (surprisingly little boilerplate code)
  • 65. From Java to Scala In Three steps
  • 66. Requirements • Person entity with age property • Method to separate minors and adults • Input: List[Person] • Output: list of minors, list of adults • One pass over input
  • 67. Requirements • Person entity with age property • Method to separate minors and adults • Input: List[Person] • Output: list of minors, list of adults • One pass over input
  • 68. What happens in the Scala Community
  • 69. Scala progression • Current version: 2.7.4 • Version 2.8 beta coming up: • Package objects • Named and default parameters • Many library improvements
  • 70. Tool support • Major IDEs (Eclipse, IntelliJ, NetBeans) supported • Maven support • Scaladoc • SBaz package manager
  • 71. Wrapping up with Concluding Remarks
  • 72. Scala hitting mainstream? Reports of first switchers Twitter, SAP, LinkedIn, Sony Pictures
  • 73. Scala hitting mainstream? Reports of first switchers Twitter, SAP, LinkedIn, Sony Pictures April 2009: top-30 of TIOBE index
  • 74. Scala hitting mainstream? Reports of first switchers Twitter, SAP, LinkedIn, Sony Pictures April 2009: top-30 of TIOBE index Lots of books appearing
  • 75. Scala hitting mainstream? “If I were to pick a language today other than Java, it would be Scala” James Gosling, ‘Father of Java’
  • 76. Scala hitting mainstream? “If Java programmers want to use features that aren't present in the language, I think they're probably best off using another language that targets the JVM, such a Scala and Groovy.” Joshua Bloch Author of ‘Effective Java’
  • 77. Pro’s and cons • Complexity • Java interoperability • Java -> Scala • Hides accidental complexity harder than Scala -> Java • Expressiveness • Type-system may • Uniform, extensible be intimidating language
  • 78. Conclusion • Scala feels like ‘cleaned up Java on stereoids’ • Small core (takes some time to see it as such) provides broad options • Type inference brings ‘dynamic language’ feel • Adoptation growing because of: • Java interoperability • Growing discontent with Java
  • 79. Conclusion • Scala feels like ‘cleaned up Java on stereoids’ • Small core (takes some time to see it as such) provides broad options • Type inference brings ‘dynamic language’ feel • Adoptation growing because of: • Java interoperability • Growing discontent with Java Scala provides deep features, but at the same time helps getting things done.
  • 80. More information http://www.scala-lang.org http://liftweb.net Article Java Magazine 1/2009

Editor's Notes

  1. Intro, gaan het hebben over Scala Wellicht al eens gehoord over FP, lijkt groeiende interesse wat is imperatief? Ook wel procedureel, met state, het is wat we in Java eigenlijk doen.
  2. Intro, gaan het hebben over Scala Wellicht al eens gehoord over FP, lijkt groeiende interesse wat is imperatief? Ook wel procedureel, met state, het is wat we in Java eigenlijk doen.
  3. Intro, gaan het hebben over Scala Wellicht al eens gehoord over FP, lijkt groeiende interesse wat is imperatief? Ook wel procedureel, met state, het is wat we in Java eigenlijk doen.
  4. Odersky: co-designer generics, original author javac. Wellicht had hier oracle logo moeten staan :)
  5. *Voordelen JVM (enorm veel tijd in optimalisatie, platform agnostisch etc.), ook wat nadelen (niet echt ingericht op FP constructies). * OO, maar dan ook puur, en met extra functionaliteit * Scripting: REPL shell
  6. Scala redelijk uniek in samenvoegen OO+FP OCaml en F# zijn toch meer FP met een OO systeem er aan geplakt.
  7. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  8. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  9. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  10. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  11. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  12. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  13. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  14. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  15. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  16. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  17. Recursie niet alleen in functies, ook in data (bomen, lijsten)
  18. Nieuwe paradigma&#x2019;s hebben killer-app nodig OO had GUIs, bij FP concurrency? Typesysteem: niet noodzakelijk voor FP, traditioneel wel focus
  19. Zonder diep in te gaan, voor we features gaan bekijken, dit is hoe Scala FP bevat.
  20. *default modifier is public *Type after identifier, type Unit == void *zowel Scala->Java als Java->Scala interop. Dus, elkaars classes instantieren overerven etc. *Abstract class ipv interfaces
  21. Extenden van Java class (extends ook voor interfaces) Type Unit -> void in Java hashCode -> hashCode() , haakjes weglaten. Soort van autoboxing, maar beter
  22. * + is methode naam, kan je zelf op een class implementeren * Leestekens legale identifiers in Scala * Operator notatie ook te gebruiken met &#x2018;normale&#x2019; methode namen * In Java discussie: operator overloadig BigInts (en wat voor matrix etc.)? Scala: just do it.
  23. * + is methode naam, kan je zelf op een class implementeren * Leestekens legale identifiers in Scala * Operator notatie ook te gebruiken met &#x2018;normale&#x2019; methode namen * In Java discussie: operator overloadig BigInts (en wat voor matrix etc.)? Scala: just do it.
  24. * + is methode naam, kan je zelf op een class implementeren * Leestekens legale identifiers in Scala * Operator notatie ook te gebruiken met &#x2018;normale&#x2019; methode namen * In Java discussie: operator overloadig BigInts (en wat voor matrix etc.)? Scala: just do it.
  25. * + is methode naam, kan je zelf op een class implementeren * Leestekens legale identifiers in Scala * Operator notatie ook te gebruiken met &#x2018;normale&#x2019; methode namen * In Java discussie: operator overloadig BigInts (en wat voor matrix etc.)? Scala: just do it.
  26. * + is methode naam, kan je zelf op een class implementeren * Leestekens legale identifiers in Scala * Operator notatie ook te gebruiken met &#x2018;normale&#x2019; methode namen * In Java discussie: operator overloadig BigInts (en wat voor matrix etc.)? Scala: just do it.
  27. *Java statics niet echt OO. Scala: Classes->te instantieren, singleton objects->&#xE9;&#xE9;n instantie *Zelfde naam: companions -> toegang tot private members *haakjes mogen weg bij methode aanroep zonder params; puntkomma&#x2019;s ook optioneel! *main methode op object Main, entrypoint applicatie
  28. * Vorige slide goed opgelet: geen return type!
  29. * Zijn natuurlijk allemaal op ISKA over closures geweest, maar toch een opfrisser * Java heeft Anon. classes -> beperkingen, verbose (interface nodig), daarom weinig gebruikt
  30. * Zijn natuurlijk allemaal op ISKA over closures geweest, maar toch een opfrisser * Java heeft Anon. classes -> beperkingen, verbose (interface nodig), daarom weinig gebruikt
  31. * Zijn natuurlijk allemaal op ISKA over closures geweest, maar toch een opfrisser * Java heeft Anon. classes -> beperkingen, verbose (interface nodig), daarom weinig gebruikt
  32. * Zijn natuurlijk allemaal op ISKA over closures geweest, maar toch een opfrisser * Java heeft Anon. classes -> beperkingen, verbose (interface nodig), daarom weinig gebruikt
  33. * Function0 tot Function22 op deze manier beschikbaar
  34. * Function0 tot Function22 op deze manier beschikbaar
  35. * Function0 tot Function22 op deze manier beschikbaar
  36. * Function0 tot Function22 op deze manier beschikbaar
  37. * Function0 tot Function22 op deze manier beschikbaar
  38. * Function0 tot Function22 op deze manier beschikbaar
  39. * Function0 tot Function22 op deze manier beschikbaar
  40. Scala gaat nog verder, zelf control structures maken (by-name params)
  41. * First trait/class with extends, then 0 or more times with * Traits can have any member: defs, abstract defs, fields traits can extend from each other
  42. * Traits are used in this fashion a lot for the Scala collection libs
  43. * abstract override: target of super not known at design-time! * calls resolve right-to-left * selftype annotation: type of this can assume type of class where trait is mixed in!
  44. * abstract override: target of super not known at design-time! * calls resolve right-to-left * selftype annotation: type of this can assume type of class where trait is mixed in!
  45. * abstract override: target of super not known at design-time! * calls resolve right-to-left * selftype annotation: type of this can assume type of class where trait is mixed in!
  46. * geen new keyword nodig: case class is class + companion object met apply method! * Sealed abstract class: compiler kan checken of alle cases gedekt zijn
  47. * geen new keyword nodig: case class is class + companion object met apply method! * Sealed abstract class: compiler kan checken of alle cases gedekt zijn
  48. * geen new keyword nodig: case class is class + companion object met apply method! * Sealed abstract class: compiler kan checken of alle cases gedekt zijn
  49. * Twee doelen: selecteren goede case, en binden van variabelen in 1 stap * Java kent heeeel beperkte pattern matching: catch-clauses * Geen NPE: helaas heeft Scala wel null, vanwege compatibility -> tradeoff * voorbeelden van option: Map.get, List.find, parseInt, etc.
  50. * Twee doelen: selecteren goede case, en binden van variabelen in 1 stap * Java kent heeeel beperkte pattern matching: catch-clauses * Geen NPE: helaas heeft Scala wel null, vanwege compatibility -> tradeoff * voorbeelden van option: Map.get, List.find, parseInt, etc.
  51. * match is an expression too
  52. * Of course case objects can be used to implement enums
  53. * Of course case objects can be used to implement enums
  54. * Of course case objects can be used to implement enums
  55. * Of course case objects can be used to implement enums
  56. * Of course case objects can be used to implement enums
  57. Ook test frameworks
  58. Proberen stukje realworld code van Java->Scala als Java programmeur->Idiomatische Scala
  59. * TIOBE top-30: beating Groovy, Haskell
  60. * TIOBE top-30: beating Groovy, Haskell
  61. Java -> Scala voorbeeld: een Scala - methode wordt vertaald naar $minus$. Veel conventies voor compiler gegenereerde classes.