SlideShare uma empresa Scribd logo
1 de 46
A first date with Scala Franco Lombardo XP User Group - Bergamo http://www.francolombardo.net Edward Hopper - Summertime
First of all, you must know… http://www.francolombardo.net … I’m not a Guru!!!
Scala: passport ,[object Object],[object Object],[object Object],[object Object],http://www.francolombardo.net Claudio Destito – Auto-ritratto
Scala = SCAlable LAnguage http://www.francolombardo.net In order to “scale” you need solid basis! ,[object Object],[object Object],[object Object],The base of Scala is Java
Here is our star: Hello World!!! http://www.francolombardo.net package   hello import   java . util .Date object   Hello   extends   Application  { println ( "Yet another Hello World program" ) val   jvmVer  =  System . getProperty ( "java.version" ) println ( "Running on JMV "   +   jvmVer ) println ( "On "   +   new   Date ()) } Yet another Hello World program Running on JMV 1.6.0_13 On Sat May 23 17:36:34 CEST 2009 Output
Here is our star: Hello World!!! http://www.francolombardo.net package   hello import   java . util .Date object   Hello   extends   Application  { println ( "Yet another Hello World program" ) val   jvmVer  =  System . getProperty ( "java.version" ) println ( "Running on JMV "   +   jvmVer ) println ( "On "   +   new   Date ()) } Basic syntax very close to Java
Here is our star: Hello World!!! http://www.francolombardo.net package   hello import   java . util .Date object   Hello   extends   Application  { println ( "Yet another Hello World program" ) val   jvmVer  =  System . getProperty ( "java.version" ) println ( "Running on JMV "   +   jvmVer ) println ( "On "   +   new   Date ()) } Object from java.lang are imported by default
Here is our star: Hello World!!! http://www.francolombardo.net package   hello import   java . util .Date object   Hello   extends   Application  { println ( "Yet another Hello World program" ) val   jvmVer  =  System . getProperty ( "java.version" ) println ( "Running on JMV "   +   jvmVer ) println ( "On "   +   new   Date ()) } Object from Java libraries are easly avaible
Here is our star: Hello World!!! http://www.francolombardo.net package   hello import   java . util .Date object   Hello   extends   Application  { println ( "Yet another Hello World program" ) val   jvmVer  =  System . getProperty ( "java.version" ) println ( "Running on JMV "   +   jvmVer ) println ( "On "   +   new   Date ()) } Simplified syntax: semicolon is not mandatory
Here is our star: Hello World!!! http://www.francolombardo.net package   hello import   java . util .Date object   Hello   extends   Application  { println ( "Yet another Hello World program" ) val   jvmVer  =  System . getProperty ( "java.version" ) println ( "Running on JMV "   +   jvmVer ) println ( "On "   +   new   Date ()) } Simplified syntax: less code
Here is our star: Hello World!!! http://www.francolombardo.net package   hello import   java . util .Date object   Hello   extends   Application  { println ( "Yet another Hello World program" ) val   jvmVer  =  System . getProperty ( "java.version" ) println ( "Running on JMV "   +   jvmVer ) println ( "On "   +   new   Date ()) } Simplified syntax: type inference
Type inference: have you ever seen it? http://www.francolombardo.net //Java return  customer.getOrder(40) .getRow(20) .getItem() .getWeight() * 2.5; (OK, in this example we do not obey Demeter law, but it’s only an example…  )
Tools for scalability:  static typing http://www.francolombardo.net ,[object Object],[object Object],[object Object],[object Object]
Tools for scalbility:  “pure” Object Orientation http://www.francolombardo.net ,[object Object],[object Object],2  +  5 //equals to... 2. + (5) ,[object Object],[object Object],[object Object]
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net ,[object Object],Fernando Botero – Bailerina na barra
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net //Java public   class  Customer { public  String name() { //some implementation… } public  String address() { //some implementation } ,[object Object]
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net //Java public   class  Customer { //… public  Bank preferredBank() { //some implementation… } public  Solvability solvability() { //some implementation… } ,[object Object]
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net //Java public   class  Customer { //… public  Agent zoneAgent() { //some implementation… } public  Boolean isToSendEMails() { //some implementation… } ,[object Object]
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net //Java public   class  Customer { //… public  Carrier[] carriers() { //some implementation… } public  Discount[] discounts() { //some implementation… } ,[object Object]
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net //Java public   class  Customer { //… public  Priority schedulingPriority() { //some implementation… } public  TechnicalInfo[] standards() { //some implementation… } ,[object Object]
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net ,[object Object],Customer name() address() AccountingCustomer preferredBank() solvability() CRMCustomer zoneAgent() isToSendEMails() ProductionCustomer schedulingPriority() standards() ,[object Object]
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net //Scala case   class   Customer ( name :  String , address :  String ) trait   accountingCstomer  { def   preferredBank  =  //some implementation def   solvability  =  //some implementation } trait   CRMCustomer  { def   zoneAgent  =  //some implementation def   isToSendEMail  =  //implementation } ,[object Object]
Tools for scalability:  Object Orientation with Traits http://www.francolombardo.net //Scala val   customer  =  new   Customer ( “Lombardo ltd" , “ Wall Street, 1" )  with   CRMCustomer   with   AccountingCustomer ,[object Object],“ Dynamic” type composition
Tools for scalability:  functional programming http://www.francolombardo.net ,[object Object],[object Object],You can decompose the system in generic functions which you can reuse reducing duplications Higher order functions
Tools for scalability:  functional programming http://www.francolombardo.net ,[object Object],[object Object],[object Object],[object Object],Referential transparency
Tools for scalability:  functional programming http://www.francolombardo.net An example: numeric integration…
Tools for scalability:  functional programming http://www.francolombardo.net … I was joking, let’s use a more “concrete” example //Here’s an order row case   class   OrderRow ( description :  String ,  price :  Double ,  qty :  Double ) { def   amount  =  price   *   qty } //And an order val   order  =  List ( OrderRow ( "Beer" , 5.0, 2),  OrderRow ( "Chips" , 2.5, 1))
Tools for scalability:  functional programming http://www.francolombardo.net //A traditional approach to VAT computation var   total  = 0.0 for  ( row  <-  order ) { total   +=   row . amount   * 0.2 } println ( &quot;VAT (Total): &quot;   +   total );
Tools for scalability:  functional programming http://www.francolombardo.net //A traditional approach to VAT computation var   total  = 0.0 for  ( row  <-  order ) { total   +=   row . amount   * 0.2 } println ( &quot;VAT (Total): &quot;   +   total ); ,[object Object],[object Object]
Tools for scalability:  functional programming http://www.francolombardo.net //A traditional approach to VAT computation var   total  = 0.0 for  ( row  <-  order ) { total   +=   row . amount   * 0.2 } println ( &quot;VAT (Total): &quot;   +   total ); ,[object Object],[object Object],[object Object]
Tools for scalability:  functional programming http://www.francolombardo.net //A traditional approach to VAT computation var   total  = 0.0 for  ( row  <-  order ) { total   +=   row . amount   * 0.2 } println ( &quot;VAT (Total): &quot;   +   total ); ,[object Object],[object Object],[object Object],[object Object]
Tools for scalability:  functional programming http://www.francolombardo.net //The computation: it’s a function we can assign val   vat  = ( row :  OrderRow ) =>  row . amount   *  0.2 //Composition of accumulation and computation def   composition ( aggr : ( Double ,  Double ) =>  Double , calculus : ( OrderRow  =>  Double )) ( partial :  Double ,  row :  OrderRow ) = aggr ( partial ,  calculus ( row )) val  totalVat = order . foldLeft (0.0)( composition (_ + _,  vat )) Let’s decompose these 3 operations
Tools for scalability:  functional programming http://www.francolombardo.net val  totalVat = order . foldLeft (0.0)( composition (_ + _,  vat )) Let’s decompose these 3 operations ,[object Object],//Java B b = start; for ( final  A a : listOfA) { b  = method( b ,  a ); } return  b; //Scala listOfA . foldLeft(start)(method)
Tools for scalability:  functional programming http://www.francolombardo.net val  totalVat = order . foldLeft (0.0)( composition (_ + _,  vat )) Let’s decompose these 3 operations ,[object Object],[object Object]
Tools for scalability:  functional programming http://www.francolombardo.net val  totalVat = order . foldLeft (0.0)( composition (_ + _,  vat )) Let’s decompose these 3 operations ,[object Object],[object Object],[object Object]
Tools for scalability:  functional programming http://www.francolombardo.net val  totalAmount = order . foldLeft (0.0)( composition (_ + _,  _. amount )) val  maxAmount = order . foldLeft (0.0)( composition ( Math . max ,  _. amount )) val  maxVat = order . foldLeft (0.0)( composition ( Math . max ,  vat )) We can recompose them in a different way
Structural types http://www.francolombardo.net def   deleteAllRows ( statement :  java . sql . Statement ) =  statement . execute ( &quot;DELETE FROM MYTABLE&quot; ) How can we test this method? An hand written mock?  The java.sql.Statement interface has 41 methods!!! (Well, I don’t like frameworks…)
Structural types http://www.francolombardo.net def   deleteAllRows ( statement : { def   execute ( sql : String):  Boolean }) =  statement . execute ( &quot;DELETE FROM MYTABLE&quot; ) Let’s modify our method declaring only what we need
Structural types http://www.francolombardo.net def   testDeleteAllRows () { val   mockStatement  =  new  { def   execute ( sql :  String ) = { println ( sql )  //Oppure qualsiasi cosa x test true   //Valore di ritorno di execute } } deleteAllRows ( mockStatement ) } Now we can test our code easily
Implicit conversions http://www.francolombardo.net class   RemoteStatement  { def   remoteExecute ( sql :  String ) = { println ( sql   +   &quot; executed remotely :-)&quot; ) true } } What if we’d need to use a library for doing remote queries?
Implicit conversions http://www.francolombardo.net implicit   def   normalize ( remote :  RemoteStatement ) = new  {   def   execute ( sql :  String ) = remote . remoteExecute ( sql ) } //I can use it even if it is not the exact type! deleteAllRows ( new   RemoteStatement ) No problem: we can convert on the fly!
Domain Specific Languages http://www.francolombardo.net val   tenDollars  =  (4.0  USD )  +  (6.0  USD ) I’d like to write something like this Andy Warhol– Dollar sign
Domain Specific Languages http://www.francolombardo.net abstract   class   Currency  { def   name :  String ; override   def   toString  =  name } object   Euro   extends   Currency  { def   name  = &quot;EUR&quot; } object   Dollar   extends   Currency  { def   name  =  &quot;USD&quot; } No problem!
Domain Specific Languages http://www.francolombardo.net case   class   Money [ C  <:  Currency ]( amount :  Double ,   currency :  C ) { def   +  ( otherMoney :  Money [ C ]) =  new   Money ( amount   +   otherMoney . amount , currency ) override   def   toString  =  amount   +   &quot; &quot;   +   currency } No problem!
Domain Specific Languages http://www.francolombardo.net object   Money  { implicit   def   doubleConverter ( d :  Double ) =  new  { def   EUR  = { new   Money ( d ,  Euro ) } def   USD  = { new   Money ( d ,  Dollar ) } } No problem!
Domain Specific Languages http://www.francolombardo.net object   Playground   extends   BasicClass  { def   main ( args :  Array [ String ]) {  10  PRINT   &quot;SCALA ROCKS!&quot; 20  GOTO  10 RUN } } With these tools we can write very exciting DSLs! Example created by Szymon Jachim See http://www.scala-lang.org/node/1403

Mais conteúdo relacionado

Mais procurados

Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great JusticeDomenic Denicola
 
JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional APIJustin Lin
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introductionb0ris_1
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignVictor Rentea
 
Building Progressive Web Apps for Windows devices
Building Progressive Web Apps for Windows devicesBuilding Progressive Web Apps for Windows devices
Building Progressive Web Apps for Windows devicesWindows Developer
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to javaciklum_ods
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloadingHaresh Jaiswal
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator OverloadingHadziq Fabroyir
 
Zend Studio Tips and Tricks
Zend Studio Tips and TricksZend Studio Tips and Tricks
Zend Studio Tips and TricksRoy Ganor
 
EclipseCon France 2016 - Sirius 4.0: Let me Sirius that for you!
EclipseCon France 2016 - Sirius 4.0: Let me Sirius that for you!EclipseCon France 2016 - Sirius 4.0: Let me Sirius that for you!
EclipseCon France 2016 - Sirius 4.0: Let me Sirius that for you!melbats
 
Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable ObjectsVictor Rentea
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingKamal Acharya
 
Kotlin For Android - Properties (part 4 of 7)
Kotlin For Android - Properties (part 4 of 7)Kotlin For Android - Properties (part 4 of 7)
Kotlin For Android - Properties (part 4 of 7)Gesh Markov
 
Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & PromisesKnoldus Inc.
 
operator overloading
operator overloadingoperator overloading
operator overloadingNishant Joshi
 
SiriusCon 2015 - Breathe Life into Your Designer!
SiriusCon 2015 - Breathe Life into Your Designer!SiriusCon 2015 - Breathe Life into Your Designer!
SiriusCon 2015 - Breathe Life into Your Designer!melbats
 
Effective C++/WinRT for UWP and Win32
Effective C++/WinRT for UWP and Win32Effective C++/WinRT for UWP and Win32
Effective C++/WinRT for UWP and Win32Windows Developer
 

Mais procurados (20)

operator overloading
operator overloadingoperator overloading
operator overloading
 
Unit Testing for Great Justice
Unit Testing for Great JusticeUnit Testing for Great Justice
Unit Testing for Great Justice
 
JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
 
Advance JS and oop
Advance JS and oopAdvance JS and oop
Advance JS and oop
 
Spring AOP Introduction
Spring AOP IntroductionSpring AOP Introduction
Spring AOP Introduction
 
The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
Building Progressive Web Apps for Windows devices
Building Progressive Web Apps for Windows devicesBuilding Progressive Web Apps for Windows devices
Building Progressive Web Apps for Windows devices
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
06. operator overloading
06. operator overloading06. operator overloading
06. operator overloading
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
 
Zend Studio Tips and Tricks
Zend Studio Tips and TricksZend Studio Tips and Tricks
Zend Studio Tips and Tricks
 
EclipseCon France 2016 - Sirius 4.0: Let me Sirius that for you!
EclipseCon France 2016 - Sirius 4.0: Let me Sirius that for you!EclipseCon France 2016 - Sirius 4.0: Let me Sirius that for you!
EclipseCon France 2016 - Sirius 4.0: Let me Sirius that for you!
 
Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable Objects
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Kotlin For Android - Properties (part 4 of 7)
Kotlin For Android - Properties (part 4 of 7)Kotlin For Android - Properties (part 4 of 7)
Kotlin For Android - Properties (part 4 of 7)
 
Scala Future & Promises
Scala Future & PromisesScala Future & Promises
Scala Future & Promises
 
operator overloading
operator overloadingoperator overloading
operator overloading
 
SiriusCon 2015 - Breathe Life into Your Designer!
SiriusCon 2015 - Breathe Life into Your Designer!SiriusCon 2015 - Breathe Life into Your Designer!
SiriusCon 2015 - Breathe Life into Your Designer!
 
Effective C++/WinRT for UWP and Win32
Effective C++/WinRT for UWP and Win32Effective C++/WinRT for UWP and Win32
Effective C++/WinRT for UWP and Win32
 

Destaque

Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con ScalaFranco Lombardo
 
Rock scissors-paper-kata
Rock scissors-paper-kataRock scissors-paper-kata
Rock scissors-paper-kataFranco Lombardo
 
Science of happiness
Science of happinessScience of happiness
Science of happinessHappiitude
 
The Dragonfly Effect - Harnessing Social Media to Build Brands
The Dragonfly Effect - Harnessing Social Media to Build BrandsThe Dragonfly Effect - Harnessing Social Media to Build Brands
The Dragonfly Effect - Harnessing Social Media to Build BrandsAndy Smith
 
Scrum, Games and The Science of Happiness
Scrum, Games and The Science of HappinessScrum, Games and The Science of Happiness
Scrum, Games and The Science of HappinessStefano Lucantoni
 
Science of Happiness Presentation
Science of Happiness PresentationScience of Happiness Presentation
Science of Happiness PresentationJon Unal
 
The Power of Happiness
The Power of HappinessThe Power of Happiness
The Power of HappinessAndy Smith
 
Happiness Presentation
Happiness PresentationHappiness Presentation
Happiness Presentationrgonzalezjr
 

Destaque (10)

Primo Incontro Con Scala
Primo Incontro Con ScalaPrimo Incontro Con Scala
Primo Incontro Con Scala
 
Rock scissors-paper-kata
Rock scissors-paper-kataRock scissors-paper-kata
Rock scissors-paper-kata
 
Java per as400
Java per as400Java per as400
Java per as400
 
Science of happiness
Science of happinessScience of happiness
Science of happiness
 
The Dragonfly Effect - Harnessing Social Media to Build Brands
The Dragonfly Effect - Harnessing Social Media to Build BrandsThe Dragonfly Effect - Harnessing Social Media to Build Brands
The Dragonfly Effect - Harnessing Social Media to Build Brands
 
Scrum, Games and The Science of Happiness
Scrum, Games and The Science of HappinessScrum, Games and The Science of Happiness
Scrum, Games and The Science of Happiness
 
Science of Happiness Presentation
Science of Happiness PresentationScience of Happiness Presentation
Science of Happiness Presentation
 
Happiness presentation ppt
Happiness presentation pptHappiness presentation ppt
Happiness presentation ppt
 
The Power of Happiness
The Power of HappinessThe Power of Happiness
The Power of Happiness
 
Happiness Presentation
Happiness PresentationHappiness Presentation
Happiness Presentation
 

Semelhante a A First Date With Scala

Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipseanshunjain
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftOleksandr Stepanov
 
Advisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptdominion
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummaryAmal Khailtash
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesPavol Pitoňák
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingHoat Le
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
Qtp Training Deepti 3 Of 44256
Qtp Training Deepti 3 Of 44256Qtp Training Deepti 3 Of 44256
Qtp Training Deepti 3 Of 44256Azhar Satti
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicTimothy Perrett
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanizecoreygoldberg
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 

Semelhante a A First Date With Scala (20)

JavaScript
JavaScriptJavaScript
JavaScript
 
Understanding Framework Architecture using Eclipse
Understanding Framework Architecture using EclipseUnderstanding Framework Architecture using Eclipse
Understanding Framework Architecture using Eclipse
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
Advisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScriptAdvisor Jumpstart: JavaScript
Advisor Jumpstart: JavaScript
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile Devices
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
eXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction TrainingeXo SEA - JavaScript Introduction Training
eXo SEA - JavaScript Introduction Training
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Qtp Training Deepti 3 Of 44256
Qtp Training Deepti 3 Of 44256Qtp Training Deepti 3 Of 44256
Qtp Training Deepti 3 Of 44256
 
Qtp Training
Qtp Training Qtp Training
Qtp Training
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Javazone 2010-lift-framework-public
Javazone 2010-lift-framework-publicJavazone 2010-lift-framework-public
Javazone 2010-lift-framework-public
 
Performance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-MechanizePerformance and Scalability Testing with Python and Multi-Mechanize
Performance and Scalability Testing with Python and Multi-Mechanize
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 

Mais de Franco Lombardo

Kotlin from-scratch 3 - coroutines
Kotlin from-scratch 3 - coroutinesKotlin from-scratch 3 - coroutines
Kotlin from-scratch 3 - coroutinesFranco Lombardo
 
Kotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsKotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsFranco Lombardo
 
Agile Venture Milan - Unit testing on AS400? Yes we can! (With Kotlin)
Agile Venture Milan - Unit testing on AS400? Yes we can! (With Kotlin)Agile Venture Milan - Unit testing on AS400? Yes we can! (With Kotlin)
Agile Venture Milan - Unit testing on AS400? Yes we can! (With Kotlin)Franco Lombardo
 
Unit testing on AS400? Yes we can! (With Kotlin)
Unit testing on AS400? Yes we can! (With Kotlin)Unit testing on AS400? Yes we can! (With Kotlin)
Unit testing on AS400? Yes we can! (With Kotlin)Franco Lombardo
 
Interprete Kotlin per l’RPG e libreria Web Components: Open Source per la m...
Interprete Kotlin per l’RPG  e libreria Web Components: Open Source per  la m...Interprete Kotlin per l’RPG  e libreria Web Components: Open Source per  la m...
Interprete Kotlin per l’RPG e libreria Web Components: Open Source per la m...Franco Lombardo
 
TDD su AS400? Con Kotlin si può fare! - Italian Agile Days 2019
TDD su AS400? Con Kotlin si può fare! - Italian Agile Days 2019TDD su AS400? Con Kotlin si può fare! - Italian Agile Days 2019
TDD su AS400? Con Kotlin si può fare! - Italian Agile Days 2019Franco Lombardo
 
Un interprete Kotlin per il linguaggio RPG AS400 - IBM i
Un interprete Kotlin per il linguaggio RPG AS400 - IBM iUn interprete Kotlin per il linguaggio RPG AS400 - IBM i
Un interprete Kotlin per il linguaggio RPG AS400 - IBM iFranco Lombardo
 
Agile Happiness - Agile O'Day 2018
Agile Happiness - Agile O'Day 2018Agile Happiness - Agile O'Day 2018
Agile Happiness - Agile O'Day 2018Franco Lombardo
 

Mais de Franco Lombardo (12)

happiness_2023.pdf
happiness_2023.pdfhappiness_2023.pdf
happiness_2023.pdf
 
Kotlin from-scratch 3 - coroutines
Kotlin from-scratch 3 - coroutinesKotlin from-scratch 3 - coroutines
Kotlin from-scratch 3 - coroutines
 
Kotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsKotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functions
 
Kotlin from-scratch
Kotlin from-scratchKotlin from-scratch
Kotlin from-scratch
 
Agile Venture Milan - Unit testing on AS400? Yes we can! (With Kotlin)
Agile Venture Milan - Unit testing on AS400? Yes we can! (With Kotlin)Agile Venture Milan - Unit testing on AS400? Yes we can! (With Kotlin)
Agile Venture Milan - Unit testing on AS400? Yes we can! (With Kotlin)
 
Unit testing on AS400? Yes we can! (With Kotlin)
Unit testing on AS400? Yes we can! (With Kotlin)Unit testing on AS400? Yes we can! (With Kotlin)
Unit testing on AS400? Yes we can! (With Kotlin)
 
Interprete Kotlin per l’RPG e libreria Web Components: Open Source per la m...
Interprete Kotlin per l’RPG  e libreria Web Components: Open Source per  la m...Interprete Kotlin per l’RPG  e libreria Web Components: Open Source per  la m...
Interprete Kotlin per l’RPG e libreria Web Components: Open Source per la m...
 
TDD su AS400? Con Kotlin si può fare! - Italian Agile Days 2019
TDD su AS400? Con Kotlin si può fare! - Italian Agile Days 2019TDD su AS400? Con Kotlin si può fare! - Italian Agile Days 2019
TDD su AS400? Con Kotlin si può fare! - Italian Agile Days 2019
 
Un interprete Kotlin per il linguaggio RPG AS400 - IBM i
Un interprete Kotlin per il linguaggio RPG AS400 - IBM iUn interprete Kotlin per il linguaggio RPG AS400 - IBM i
Un interprete Kotlin per il linguaggio RPG AS400 - IBM i
 
Agile Happiness - Agile O'Day 2018
Agile Happiness - Agile O'Day 2018Agile Happiness - Agile O'Day 2018
Agile Happiness - Agile O'Day 2018
 
Agile Happiness 2
Agile Happiness 2Agile Happiness 2
Agile Happiness 2
 
Agile Happiness
Agile HappinessAgile Happiness
Agile Happiness
 

Último

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Último (20)

WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

A First Date With Scala

  • 1. A first date with Scala Franco Lombardo XP User Group - Bergamo http://www.francolombardo.net Edward Hopper - Summertime
  • 2. First of all, you must know… http://www.francolombardo.net … I’m not a Guru!!!
  • 3.
  • 4.
  • 5. Here is our star: Hello World!!! http://www.francolombardo.net package hello import java . util .Date object Hello extends Application { println ( &quot;Yet another Hello World program&quot; ) val jvmVer = System . getProperty ( &quot;java.version&quot; ) println ( &quot;Running on JMV &quot; + jvmVer ) println ( &quot;On &quot; + new Date ()) } Yet another Hello World program Running on JMV 1.6.0_13 On Sat May 23 17:36:34 CEST 2009 Output
  • 6. Here is our star: Hello World!!! http://www.francolombardo.net package hello import java . util .Date object Hello extends Application { println ( &quot;Yet another Hello World program&quot; ) val jvmVer = System . getProperty ( &quot;java.version&quot; ) println ( &quot;Running on JMV &quot; + jvmVer ) println ( &quot;On &quot; + new Date ()) } Basic syntax very close to Java
  • 7. Here is our star: Hello World!!! http://www.francolombardo.net package hello import java . util .Date object Hello extends Application { println ( &quot;Yet another Hello World program&quot; ) val jvmVer = System . getProperty ( &quot;java.version&quot; ) println ( &quot;Running on JMV &quot; + jvmVer ) println ( &quot;On &quot; + new Date ()) } Object from java.lang are imported by default
  • 8. Here is our star: Hello World!!! http://www.francolombardo.net package hello import java . util .Date object Hello extends Application { println ( &quot;Yet another Hello World program&quot; ) val jvmVer = System . getProperty ( &quot;java.version&quot; ) println ( &quot;Running on JMV &quot; + jvmVer ) println ( &quot;On &quot; + new Date ()) } Object from Java libraries are easly avaible
  • 9. Here is our star: Hello World!!! http://www.francolombardo.net package hello import java . util .Date object Hello extends Application { println ( &quot;Yet another Hello World program&quot; ) val jvmVer = System . getProperty ( &quot;java.version&quot; ) println ( &quot;Running on JMV &quot; + jvmVer ) println ( &quot;On &quot; + new Date ()) } Simplified syntax: semicolon is not mandatory
  • 10. Here is our star: Hello World!!! http://www.francolombardo.net package hello import java . util .Date object Hello extends Application { println ( &quot;Yet another Hello World program&quot; ) val jvmVer = System . getProperty ( &quot;java.version&quot; ) println ( &quot;Running on JMV &quot; + jvmVer ) println ( &quot;On &quot; + new Date ()) } Simplified syntax: less code
  • 11. Here is our star: Hello World!!! http://www.francolombardo.net package hello import java . util .Date object Hello extends Application { println ( &quot;Yet another Hello World program&quot; ) val jvmVer = System . getProperty ( &quot;java.version&quot; ) println ( &quot;Running on JMV &quot; + jvmVer ) println ( &quot;On &quot; + new Date ()) } Simplified syntax: type inference
  • 12. Type inference: have you ever seen it? http://www.francolombardo.net //Java return customer.getOrder(40) .getRow(20) .getItem() .getWeight() * 2.5; (OK, in this example we do not obey Demeter law, but it’s only an example…  )
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26. Tools for scalability: functional programming http://www.francolombardo.net An example: numeric integration…
  • 27. Tools for scalability: functional programming http://www.francolombardo.net … I was joking, let’s use a more “concrete” example //Here’s an order row case class OrderRow ( description : String , price : Double , qty : Double ) { def amount = price * qty } //And an order val order = List ( OrderRow ( &quot;Beer&quot; , 5.0, 2), OrderRow ( &quot;Chips&quot; , 2.5, 1))
  • 28. Tools for scalability: functional programming http://www.francolombardo.net //A traditional approach to VAT computation var total = 0.0 for ( row <- order ) { total += row . amount * 0.2 } println ( &quot;VAT (Total): &quot; + total );
  • 29.
  • 30.
  • 31.
  • 32. Tools for scalability: functional programming http://www.francolombardo.net //The computation: it’s a function we can assign val vat = ( row : OrderRow ) => row . amount * 0.2 //Composition of accumulation and computation def composition ( aggr : ( Double , Double ) => Double , calculus : ( OrderRow => Double )) ( partial : Double , row : OrderRow ) = aggr ( partial , calculus ( row )) val totalVat = order . foldLeft (0.0)( composition (_ + _, vat )) Let’s decompose these 3 operations
  • 33.
  • 34.
  • 35.
  • 36. Tools for scalability: functional programming http://www.francolombardo.net val totalAmount = order . foldLeft (0.0)( composition (_ + _, _. amount )) val maxAmount = order . foldLeft (0.0)( composition ( Math . max , _. amount )) val maxVat = order . foldLeft (0.0)( composition ( Math . max , vat )) We can recompose them in a different way
  • 37. Structural types http://www.francolombardo.net def deleteAllRows ( statement : java . sql . Statement ) = statement . execute ( &quot;DELETE FROM MYTABLE&quot; ) How can we test this method? An hand written mock? The java.sql.Statement interface has 41 methods!!! (Well, I don’t like frameworks…)
  • 38. Structural types http://www.francolombardo.net def deleteAllRows ( statement : { def execute ( sql : String): Boolean }) = statement . execute ( &quot;DELETE FROM MYTABLE&quot; ) Let’s modify our method declaring only what we need
  • 39. Structural types http://www.francolombardo.net def testDeleteAllRows () { val mockStatement = new { def execute ( sql : String ) = { println ( sql ) //Oppure qualsiasi cosa x test true //Valore di ritorno di execute } } deleteAllRows ( mockStatement ) } Now we can test our code easily
  • 40. Implicit conversions http://www.francolombardo.net class RemoteStatement { def remoteExecute ( sql : String ) = { println ( sql + &quot; executed remotely :-)&quot; ) true } } What if we’d need to use a library for doing remote queries?
  • 41. Implicit conversions http://www.francolombardo.net implicit def normalize ( remote : RemoteStatement ) = new { def execute ( sql : String ) = remote . remoteExecute ( sql ) } //I can use it even if it is not the exact type! deleteAllRows ( new RemoteStatement ) No problem: we can convert on the fly!
  • 42. Domain Specific Languages http://www.francolombardo.net val tenDollars = (4.0 USD ) + (6.0 USD ) I’d like to write something like this Andy Warhol– Dollar sign
  • 43. Domain Specific Languages http://www.francolombardo.net abstract class Currency { def name : String ; override def toString = name } object Euro extends Currency { def name = &quot;EUR&quot; } object Dollar extends Currency { def name = &quot;USD&quot; } No problem!
  • 44. Domain Specific Languages http://www.francolombardo.net case class Money [ C <: Currency ]( amount : Double , currency : C ) { def + ( otherMoney : Money [ C ]) = new Money ( amount + otherMoney . amount , currency ) override def toString = amount + &quot; &quot; + currency } No problem!
  • 45. Domain Specific Languages http://www.francolombardo.net object Money { implicit def doubleConverter ( d : Double ) = new { def EUR = { new Money ( d , Euro ) } def USD = { new Money ( d , Dollar ) } } No problem!
  • 46. Domain Specific Languages http://www.francolombardo.net object Playground extends BasicClass { def main ( args : Array [ String ]) { 10 PRINT &quot;SCALA ROCKS!&quot; 20 GOTO 10 RUN } } With these tools we can write very exciting DSLs! Example created by Szymon Jachim See http://www.scala-lang.org/node/1403