SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
Introduktion till
                          Catchy och humoristisk undertitel




             Johan Andrén
             @apnylle
             johan.andren@mejsla.se


onsdag, 25 april 2012
Vem är jag?
                        Fil Mag
                        Datavetenskap
                        Hyffsat nördig
                        Mejsla
                        6 år Java
                        1 år Scala       @apnylle




onsdag, 25 april 2012
Disclaimer
         Om du fattar några som helst affärsbeslut, skaffar dig
       några som helst åsikter (positiva eller negativa) eller blir
       av med stora mängder fritid som en följd av vad jag sagt
       idag så tänk på att det är fullt möjligt att jag i framtiden,
           om jag konfronteras med det, kan komma att helt
        förneka att jag någonsin sagt det jag sagt idag - om det
          inte handlar om beröm eller någon form av positiv
       uppmärksamhet i vilket fall jag kan komma att acceptera
          att saker jag inte sagt idag tillskrivs mig som åsikter.


onsdag, 25 april 2012
Vad är                             ?
                        Ett alternativt språk för JVM
                        Ett hybridspråk: OO + Funktionellt
                        Både scriptspråk och kompilerat
                        Statiskt typat
                        Nyheterna i Java 8, 9 och 10 - idag



onsdag, 25 april 2012
Jämfört med Java
                        ”Pure OO” - Inga primitiver, inga statics
                        Koncisare syntax - mindre ceremoni/boilerplate
                        Typinferens
                        Operatoröverlagring - typ
                        Lambdauttryck
                        Pattern matching (switch på stereoider)
                        ”Duck typing”/Structural types


onsdag, 25 april 2012
Interoperabilitet

                        Kompilerad Scala-kod blir .class-filer
                        Att ropa på Java-kod, ärva från Javaklasser
                        etc. kräver inget extra arbete
                        Att ropa på Scala-kod från Java-kod möjligt




onsdag, 25 april 2012
Jaja, visa kod nu!


onsdag, 25 april 2012
Javakod i Scala
        Java                            Scala




          Funktionsdeklaration:

            [access] def namn(a: TypFörA, b: TypFörB): Returtyp = {

                        ...

             }


onsdag, 25 april 2012
Javakod i Scala
        Java                         Scala




          Variabeldeklaration:
            var namn: Typ = värde

             val namn: Typ = värde


onsdag, 25 april 2012
Javakod i Scala
        Java                   Scala




onsdag, 25 april 2012
Mer kod?




onsdag, 25 april 2012
semikolon: valfritt




onsdag, 25 april 2012
return: valfritt




onsdag, 25 april 2012
funktion som är uttryck




onsdag, 25 april 2012
typer: (oftast) valfria




onsdag, 25 april 2012
typer: (oftast) valfria




onsdag, 25 april 2012
parenteser på parameterlösa
                            funktioner: valfritt




onsdag, 25 april 2012
Uniform Access Principle




onsdag, 25 april 2012
Returtyp på sidoeffekts-
                          funktioner: valfritt




onsdag, 25 april 2012
Default-scope (PreDef)




onsdag, 25 april 2012
Slutresultat
          Java                  Scala




onsdag, 25 april 2012
Typinferens återbesök
                                    a: Int                   items: List[String]




                          motsvarar list.get(index) i java



onsdag, 25 april 2012
OO i Scala
                        Snarlikt Java men med knorr
                         koncisare klassdeklarationer
                         case-klasser
                         Inga statiska metoder eller fält
                         traits istället för interface



onsdag, 25 april 2012
Klasser




onsdag, 25 april 2012
Case Class
         deklaration

                             apply-factory-funktion


                                                        accessor
                                                                   copy
                                                      equal+hashcode




                        unapply/extractor             toString
onsdag, 25 april 2012
onsdag, 25 april 2012
Trait

                        Som ett interface som kan innehålla kod
                         Flera kan mixas in i med en klass
                         Tvärgående funktionalitet




onsdag, 25 april 2012
onsdag, 25 april 2012
Object
                        Singleton
                         Kan skickas runt
                         Kan vara löv i arvshierarkin
                         Kan implementera trait/interface




onsdag, 25 april 2012
onsdag, 25 april 2012
Funktionell programmering
                        Matematisk funktion: sin(x)
                        Funktioner är också objekt




onsdag, 25 april 2012
Funktionell programmering
                        signatur för en parameterlös funktion med Unit som retur




                                      parameterlös funktion med Unit som retur
onsdag, 25 april 2012
FP i Scala-biblioteken




onsdag, 25 april 2012
Syntaktiskt socker




onsdag, 25 april 2012
Jämfört med Java


                               ≈




onsdag, 25 april 2012
Vad istället för hur




onsdag, 25 april 2012
Default-parametrar




onsdag, 25 april 2012
Nästlade funktioner




onsdag, 25 april 2012
Alla uttryck returnerar värden




onsdag, 25 april 2012
Tupler




onsdag, 25 april 2012
http://www.scala-lang.org
           Frågor



             Johan Andrén
             @apnylle
             johan.andren@mejsla.se


onsdag, 25 april 2012

Mais conteúdo relacionado

Mais de Johan Andrén

Next generation actors with Akka
Next generation actors with AkkaNext generation actors with Akka
Next generation actors with AkkaJohan Andrén
 
Next generation message driven systems with Akka
Next generation message driven systems with AkkaNext generation message driven systems with Akka
Next generation message driven systems with AkkaJohan Andrén
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Johan Andrén
 
Networks and types - the future of Akka
Networks and types - the future of AkkaNetworks and types - the future of Akka
Networks and types - the future of AkkaJohan Andrén
 
Reactive streams processing using Akka Streams
Reactive streams processing using Akka StreamsReactive streams processing using Akka Streams
Reactive streams processing using Akka StreamsJohan Andrén
 
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka Building reactive distributed systems with Akka
Building reactive distributed systems with Akka Johan Andrén
 
Akka streams - Umeå java usergroup
Akka streams - Umeå java usergroupAkka streams - Umeå java usergroup
Akka streams - Umeå java usergroupJohan Andrén
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams Johan Andrén
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsJohan Andrén
 
Scala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streamsScala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streamsJohan Andrén
 
VJUG24 - Reactive Integrations with Akka Streams
VJUG24  - Reactive Integrations with Akka StreamsVJUG24  - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka StreamsJohan Andrén
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8Johan Andrén
 
Scala frukostseminarium
Scala frukostseminariumScala frukostseminarium
Scala frukostseminariumJohan Andrén
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to AkkaJohan Andrén
 
Akka frukostseminarium
Akka   frukostseminariumAkka   frukostseminarium
Akka frukostseminariumJohan Andrén
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaJohan Andrén
 

Mais de Johan Andrén (16)

Next generation actors with Akka
Next generation actors with AkkaNext generation actors with Akka
Next generation actors with Akka
 
Next generation message driven systems with Akka
Next generation message driven systems with AkkaNext generation message driven systems with Akka
Next generation message driven systems with Akka
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams
 
Networks and types - the future of Akka
Networks and types - the future of AkkaNetworks and types - the future of Akka
Networks and types - the future of Akka
 
Reactive streams processing using Akka Streams
Reactive streams processing using Akka StreamsReactive streams processing using Akka Streams
Reactive streams processing using Akka Streams
 
Building reactive distributed systems with Akka
Building reactive distributed systems with Akka Building reactive distributed systems with Akka
Building reactive distributed systems with Akka
 
Akka streams - Umeå java usergroup
Akka streams - Umeå java usergroupAkka streams - Umeå java usergroup
Akka streams - Umeå java usergroup
 
Streaming all the things with akka streams
Streaming all the things with akka streams   Streaming all the things with akka streams
Streaming all the things with akka streams
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
 
Scala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streamsScala usergroup stockholm - reactive integrations with akka streams
Scala usergroup stockholm - reactive integrations with akka streams
 
VJUG24 - Reactive Integrations with Akka Streams
VJUG24  - Reactive Integrations with Akka StreamsVJUG24  - Reactive Integrations with Akka Streams
VJUG24 - Reactive Integrations with Akka Streams
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8
 
Scala frukostseminarium
Scala frukostseminariumScala frukostseminarium
Scala frukostseminarium
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to Akka
 
Akka frukostseminarium
Akka   frukostseminariumAkka   frukostseminarium
Akka frukostseminarium
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 

Duchess scala-2012