SlideShare a Scribd company logo
- en bedre og mere effektiv Java?

                     Jesper Kamstrup Linnet
                     jesper@linnet-data.dk

                     7N IT-konference 2010
                     5. maj 2010
Om mig

•Freelancekonsulent
• Java- og .NET-udvikler/arkitekt
• Sprogbegejstret
Agenda

•Hvad er Scala?
• En bedre Java?
• Ready for prime time?
Kort om Scalas historie


• Startet i 2001
• Skabt af Martin Odersky
Hvad er Scala?
En bedre Java?
Java         Scala




                  + ?
          J av a+
Er Java dødt som sprog?




                     Kilde: InfoQ.com
Kendetegn


• Statisk typet
• Skalabilitet i højsædet
Hybridsprog

         =
 Objektorienteret
         +
Funktionsorienteret
Objektorienteret



1.to(5)        Range(1, 2, 3, 4, 5)
Funktionsorienteret


          val a = 10



   val f = (x: Int) => x + 5
Immutability

•   Centralt for
    funktionsprogrammering
•   Vigtigt for parallelisering
• Letter kodelæsning
Hvad gør Scala mere
     effektivt?
Hello, world



println("Hello, world")
Syntaktisk sukker




               Image: Suat Eman / FreeDigitalPhotos.net
Kompakt syntaks (1)
            Java                           Scala
public class Person {
    private final String name;
                                    class Person(
    private final String address;   	 val name: String,
     public Person(String name,
                                    	 val address: String);
	   	 String address) {
         this.name = name;
         this.address = address;
     }

    public String getName() {
        return name;
    }

    public String getAddress() {
        return address;
    }
Kompakt syntaks (2)
                        Java                                Scala
                                                     case class Person(
public class Person {
	      private final String name;
	      private final String address;

	
	
      public Person(String name, String address) {
      	      this.name = name;
                                                     	 name: String,
                                                     	 address: String);
	     	      this.address = address;
	     }

	     public String getName() {
	     	      return name;
	     }

	     public String getAddress() {
	     	      return address;
	     }

	     @Override
	     public int hashCode() {
	     	      ...
	     }

	     @Override
	     public boolean equals(Object obj) {
	     	      ...
	     }

	     @Override
	     public String toString() {
	     	      ...
	     }
copy method ala                 2 .8
                                   Sc


val person = Person("Jesper", "Kbh")

val newPerson = person.copy(address = "Aarhus")

                            Person(Jesper,Aarhus)
Kompakt syntaks (3)
class   Car {
	 var   driven = 0.0
	
	 def   drive(distance: Double) = driven += distance
	 	
	 def   milesDriven = driven * 1.6
}

...

val car = new Car
car drive 10
Collections
val list = List(1,2,3)
val map = Map(
	 	 	 	 	 "Jesper" -> 39,
	 	 	 	 	 "Peter" -> 55
				)
val set = Set(1, 2, 5, 2)
val array = Array(1, 2, 3)
Hvad foretrækker du?
            Java                          Scala
List<Integer> numbers = ...        val numbers = ...

List<Integer> result =             val result =
	 new ArrayList<Integer>();        	 numbers filter isEven
for (Integer number : numbers) {
	 if (isEven(number) {
	 	 result.add(number);
	 }
}
Anonyme funktioner
val list = List(1,2,3,4)

list filter isEven                List(2, 4)



list filter { n => n % 2 == 0 }



list filter { _ % 2 == 0 }
Operationer på List (1)
val list = List(1,2,3,4)


list map (x => x * x)      List(1, 4, 9, 16)
list sum                   10
list mkString ","          1,2,3,4
list forall { _ < 5 }      true
list partition isEven      (List(2, 4),
                           List(1, 3))
Closures
var outside = 5
val closure = (i: Int) => i * outside

println(closure(2))                     10


outside = 10
println(closure(2))                     20
Pattern matching (1)

value match {
    case 1 => println("Tal")
    case i: Int => printf("Tallet %d", i)
    case "test" => println("Streng")
    case (x, y) => printf("Et par, x=%s, y=%s", x, y)
    case _ => println("Alt andet")
}
Pattern matching (2)
                                             Lister
value match {
    case List(_, _) => println("To elementer")
    case List(1, rest @ _*) => println("1 og flere")
}
Pattern matching (3)
                             Regulære udtryk
val Danish = "Hej (.*)".r
val English = "Hi, (.*)".r

greeting match {
	 case Danish(name) => printf("Dansk: %s", name)
	 case English(name) => printf("Engelsk: %s", name)
}
Pattern matching (4)
                                 Case classes


value match {
	 case Person(_, "Kbh") => println("Københavner")
	 case _ => println("Uden for København")
}
XML (1)


val personsXml =
	 <persons>
	 	 <person name="Jesper"><age>38</age></person>
	 	 <person name="Ulla"><age>{age}</age></person>
	 </persons>
XML (2)

val persons = personsXml  "person"

val name = person  "@name"




val names = personsXml  "@name"
XML (3)


node match {
	 case <name>{name}</name> => println(name)
	 case _ => println("Andet")
}
Duck typing




“If it walks like a duck, and quacks like a
          duck, then it is a duck”
Duck typing

public class Text extends ... {
	 public void setText (String string) {


public class Button extends ... {
	 public void setText (String string) {
Duck typing m. Scala

def update(control: { def setText(text: String) }) = {
	 	 control.setText("Hello, world")
}




type ControlWithText = { def setText(text: String) }

def update(control: ControlWithText) = {
	 control.setText("Hello, world")
}
Traits (1)
                          Som interface
trait Editable {
	 def isEditable(): Boolean
}

class EditablePerson extends Editable {
	 def isEditable() = true
}
Traits (2)
                  Definition af mixin

trait Persistable {
	 val entityManager: EntityManager = ...

	 def save = {
	 	 entityManager.persist(this)
	 }
}
Traits (3)
                    Statisk brug af mixin

class Car extends Vehicle with Persistable {
	 ...
}

val car = new Car
car.save
Traits (4)
              Dynamisk brug af mixin

class Bicycle extends Vehicle {
	 ...
}

val bicycle = new Bicycle with Persistable
bicycle.save
Traits (5)
                                   Overstyring
trait LoggingCollection extends
               java.util.Collection[String] {

	   abstract override def add(e: String) = {
	   	 printf("Adding: %s", e)
	   	 super.add(e)
	   }
}

val coll = new java.util.ArrayList[String]
                      with LoggingCollection
Traits (6)
                         Eksempel: Observer
trait Subject {
  type Observer = { def receiveUpdate(subject:Any) }

  private var observers = List[Observer]()
  def addObserver(observer:Observer) =
	 	 observers ::= observer
  def notifyObservers =
	 	 observers foreach (_.receiveUpdate(this))
}
Parallelisering

•Højere abstraktionsniveau
• Aktørmodel
• Beskedudveksling
• Share-nothing
Simpel aktør

import scala.actors.Actor._

actor {
	 calculateStuff
}

// stuff in main thread
Beskedudveksling

val parrot = actor {
	 while (true) {
	 	 receive {
	 	 	 case msg =>
	 	 	 	 println("Msg: " + msg)
	 	 }
	 }
}

parrot ! "Hello, Polly"
Ready for prime time?
Scala i den virkelige
       verden
Masser af information

• http://scala-lang.org
• Bøger

• Tutorials og artikler
Hvorfor ikke Scala?

•Ny syntaks
• “Ungt” sprog
• Værktøjsunderstøttelse
Hvorfor Scala?

•Kompatibilitet med Java
• Stærkere syntaks
• I fremgang
Hvorfor Scala?
“You only fully comprehend
the awesomeness of #scala
when after weeks of being
pure scala you have to edit
some Java again...”
           James Strachan (@jstrachan)
Konklusion


En bedre og mere
  effektiv Java?
Kontakt

•   Slides: http://bit.ly/scala-7n

• jesper@linnet-data.dk
• http://twitter.com/jesper_linnet
• http://blog.kamstrup-linnet.dk
Spørgsmål?
- en bedre og mere effektiv Java?

                     Jesper Kamstrup Linnet
                     jesper@linnet-data.dk

                     7N IT-konference 2010
                     5. maj 2010

More Related Content

What's hot

Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
Denis
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021
Jorge Vásquez
 
Joy of scala
Joy of scalaJoy of scala
Joy of scala
Maxim Novak
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
Jorge Vásquez
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
Sasidhar Kothuru
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
Xebia IT Architects
 
Benefits of Kotlin
Benefits of KotlinBenefits of Kotlin
Benefits of Kotlin
Benjamin Waye
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
Ruslan Shevchenko
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
Meetup slides
Meetup slidesMeetup slides
Meetup slides
suraj_atreya
 

What's hot (16)

Scala collections
Scala collectionsScala collections
Scala collections
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021ZIO Prelude - ZIO World 2021
ZIO Prelude - ZIO World 2021
 
JS OO and Closures
JS OO and ClosuresJS OO and Closures
JS OO and Closures
 
Joy of scala
Joy of scalaJoy of scala
Joy of scala
 
Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!Be Smart, Constrain Your Types to Free Your Brain!
Be Smart, Constrain Your Types to Free Your Brain!
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Spsl v unit - final
Spsl v unit - finalSpsl v unit - final
Spsl v unit - final
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
 
Benefits of Kotlin
Benefits of KotlinBenefits of Kotlin
Benefits of Kotlin
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
Scala
ScalaScala
Scala
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
Meetup slides
Meetup slidesMeetup slides
Meetup slides
 

Viewers also liked

Acec2014 RALfieProject
Acec2014 RALfieProjectAcec2014 RALfieProject
Acec2014 RALfieProject
Lindy (McKeown) Orwin
 
SPS 2014
SPS 2014SPS 2014
SPS 2014alain2a
 
JD Edwards - Automate Benefits Enrollment Leveraging ESS Work Files
JD Edwards - Automate Benefits Enrollment Leveraging ESS Work FilesJD Edwards - Automate Benefits Enrollment Leveraging ESS Work Files
JD Edwards - Automate Benefits Enrollment Leveraging ESS Work Files
Smartbridge
 
It's No Mystery... Mobile BI Will Rule in 2015
It's No Mystery... Mobile BI Will Rule in 2015It's No Mystery... Mobile BI Will Rule in 2015
It's No Mystery... Mobile BI Will Rule in 2015
Smartbridge
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
LinkedIn
 

Viewers also liked (6)

Acec2014 RALfieProject
Acec2014 RALfieProjectAcec2014 RALfieProject
Acec2014 RALfieProject
 
SPS 2014
SPS 2014SPS 2014
SPS 2014
 
Tiiu Maarja
Tiiu MaarjaTiiu Maarja
Tiiu Maarja
 
JD Edwards - Automate Benefits Enrollment Leveraging ESS Work Files
JD Edwards - Automate Benefits Enrollment Leveraging ESS Work FilesJD Edwards - Automate Benefits Enrollment Leveraging ESS Work Files
JD Edwards - Automate Benefits Enrollment Leveraging ESS Work Files
 
It's No Mystery... Mobile BI Will Rule in 2015
It's No Mystery... Mobile BI Will Rule in 2015It's No Mystery... Mobile BI Will Rule in 2015
It's No Mystery... Mobile BI Will Rule in 2015
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to Scala - en bedre og mere effektiv Java?

Scala introduction
Scala introductionScala introduction
Scala introduction
Yardena Meymann
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
Łukasz Bałamut
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Lorenzo Dematté
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Matthew Farwell
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
Vladimir Parfinenko
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
Eric Pederson
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
Bert Van Vreckem
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersMiles Sabin
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
BTI360
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
league
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scalashinolajla
 

Similar to Scala - en bedre og mere effektiv Java? (20)

Scala introduction
Scala introductionScala introduction
Scala introduction
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 

Recently uploaded

When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

Scala - en bedre og mere effektiv Java?

  • 1. - en bedre og mere effektiv Java? Jesper Kamstrup Linnet jesper@linnet-data.dk 7N IT-konference 2010 5. maj 2010
  • 2. Om mig •Freelancekonsulent • Java- og .NET-udvikler/arkitekt • Sprogbegejstret
  • 3. Agenda •Hvad er Scala? • En bedre Java? • Ready for prime time?
  • 4. Kort om Scalas historie • Startet i 2001 • Skabt af Martin Odersky
  • 6. En bedre Java? Java Scala + ? J av a+
  • 7. Er Java dødt som sprog? Kilde: InfoQ.com
  • 8. Kendetegn • Statisk typet • Skalabilitet i højsædet
  • 9. Hybridsprog = Objektorienteret + Funktionsorienteret
  • 10. Objektorienteret 1.to(5) Range(1, 2, 3, 4, 5)
  • 11. Funktionsorienteret val a = 10 val f = (x: Int) => x + 5
  • 12. Immutability • Centralt for funktionsprogrammering • Vigtigt for parallelisering • Letter kodelæsning
  • 13. Hvad gør Scala mere effektivt?
  • 15. Syntaktisk sukker Image: Suat Eman / FreeDigitalPhotos.net
  • 16. Kompakt syntaks (1) Java Scala public class Person { private final String name; class Person( private final String address; val name: String, public Person(String name, val address: String); String address) { this.name = name; this.address = address; } public String getName() { return name; } public String getAddress() { return address; }
  • 17. Kompakt syntaks (2) Java Scala case class Person( public class Person { private final String name; private final String address; public Person(String name, String address) { this.name = name; name: String, address: String); this.address = address; } public String getName() { return name; } public String getAddress() { return address; } @Override public int hashCode() { ... } @Override public boolean equals(Object obj) { ... } @Override public String toString() { ... }
  • 18. copy method ala 2 .8 Sc val person = Person("Jesper", "Kbh") val newPerson = person.copy(address = "Aarhus") Person(Jesper,Aarhus)
  • 19. Kompakt syntaks (3) class Car { var driven = 0.0 def drive(distance: Double) = driven += distance def milesDriven = driven * 1.6 } ... val car = new Car car drive 10
  • 20. Collections val list = List(1,2,3) val map = Map( "Jesper" -> 39, "Peter" -> 55 ) val set = Set(1, 2, 5, 2) val array = Array(1, 2, 3)
  • 21. Hvad foretrækker du? Java Scala List<Integer> numbers = ... val numbers = ... List<Integer> result = val result = new ArrayList<Integer>(); numbers filter isEven for (Integer number : numbers) { if (isEven(number) { result.add(number); } }
  • 22. Anonyme funktioner val list = List(1,2,3,4) list filter isEven List(2, 4) list filter { n => n % 2 == 0 } list filter { _ % 2 == 0 }
  • 23. Operationer på List (1) val list = List(1,2,3,4) list map (x => x * x) List(1, 4, 9, 16) list sum 10 list mkString "," 1,2,3,4 list forall { _ < 5 } true list partition isEven (List(2, 4), List(1, 3))
  • 24. Closures var outside = 5 val closure = (i: Int) => i * outside println(closure(2)) 10 outside = 10 println(closure(2)) 20
  • 25. Pattern matching (1) value match { case 1 => println("Tal") case i: Int => printf("Tallet %d", i) case "test" => println("Streng") case (x, y) => printf("Et par, x=%s, y=%s", x, y) case _ => println("Alt andet") }
  • 26. Pattern matching (2) Lister value match { case List(_, _) => println("To elementer") case List(1, rest @ _*) => println("1 og flere") }
  • 27. Pattern matching (3) Regulære udtryk val Danish = "Hej (.*)".r val English = "Hi, (.*)".r greeting match { case Danish(name) => printf("Dansk: %s", name) case English(name) => printf("Engelsk: %s", name) }
  • 28. Pattern matching (4) Case classes value match { case Person(_, "Kbh") => println("Københavner") case _ => println("Uden for København") }
  • 29. XML (1) val personsXml = <persons> <person name="Jesper"><age>38</age></person> <person name="Ulla"><age>{age}</age></person> </persons>
  • 30. XML (2) val persons = personsXml "person" val name = person "@name" val names = personsXml "@name"
  • 31. XML (3) node match { case <name>{name}</name> => println(name) case _ => println("Andet") }
  • 32. Duck typing “If it walks like a duck, and quacks like a duck, then it is a duck”
  • 33. Duck typing public class Text extends ... { public void setText (String string) { public class Button extends ... { public void setText (String string) {
  • 34. Duck typing m. Scala def update(control: { def setText(text: String) }) = { control.setText("Hello, world") } type ControlWithText = { def setText(text: String) } def update(control: ControlWithText) = { control.setText("Hello, world") }
  • 35. Traits (1) Som interface trait Editable { def isEditable(): Boolean } class EditablePerson extends Editable { def isEditable() = true }
  • 36. Traits (2) Definition af mixin trait Persistable { val entityManager: EntityManager = ... def save = { entityManager.persist(this) } }
  • 37. Traits (3) Statisk brug af mixin class Car extends Vehicle with Persistable { ... } val car = new Car car.save
  • 38. Traits (4) Dynamisk brug af mixin class Bicycle extends Vehicle { ... } val bicycle = new Bicycle with Persistable bicycle.save
  • 39. Traits (5) Overstyring trait LoggingCollection extends java.util.Collection[String] { abstract override def add(e: String) = { printf("Adding: %s", e) super.add(e) } } val coll = new java.util.ArrayList[String] with LoggingCollection
  • 40. Traits (6) Eksempel: Observer trait Subject { type Observer = { def receiveUpdate(subject:Any) } private var observers = List[Observer]() def addObserver(observer:Observer) = observers ::= observer def notifyObservers = observers foreach (_.receiveUpdate(this)) }
  • 42. Simpel aktør import scala.actors.Actor._ actor { calculateStuff } // stuff in main thread
  • 43. Beskedudveksling val parrot = actor { while (true) { receive { case msg => println("Msg: " + msg) } } } parrot ! "Hello, Polly"
  • 45. Scala i den virkelige verden
  • 46. Masser af information • http://scala-lang.org • Bøger • Tutorials og artikler
  • 47. Hvorfor ikke Scala? •Ny syntaks • “Ungt” sprog • Værktøjsunderstøttelse
  • 48. Hvorfor Scala? •Kompatibilitet med Java • Stærkere syntaks • I fremgang
  • 49. Hvorfor Scala? “You only fully comprehend the awesomeness of #scala when after weeks of being pure scala you have to edit some Java again...” James Strachan (@jstrachan)
  • 50. Konklusion En bedre og mere effektiv Java?
  • 51. Kontakt • Slides: http://bit.ly/scala-7n • jesper@linnet-data.dk • http://twitter.com/jesper_linnet • http://blog.kamstrup-linnet.dk
  • 53. - en bedre og mere effektiv Java? Jesper Kamstrup Linnet jesper@linnet-data.dk 7N IT-konference 2010 5. maj 2010