SlideShare una empresa de Scribd logo
1 de 21
Learning Scala
Aniket Joshi
1
What is Scala?
• Scala(ska-lah) stands for Scalable Language
• Combines functional programming with
Object Oriented Programming
• Growing as per the demand of the users
• Write small scripts as well as build larger
systems
2
What is Scala? Contd.
• Runs on the java platform(Java Virtual Machine)
as well as Dot net platform
• Designed by Martin Odersky in 2001 at EPFL,
who was also one of the creators of javac
compiler and generic java
• Open source
• Released in 2004
• Second version v 2.0 in 2006
• Current version 2.11.5
3
What makes Scala scalable?
• Combining OOP with functional programming
4
Why OOP?
• Purely OO
• Every operation is method
• Every value is an object
• No primitive types, everything is an object
• 1+2 invokes a method + defined in the class
Int
5
What is Functional Programming(FP)?
• “In computer science, functional programming is a programming
paradigm, a style of building the structure and elements of computer
programs, that treats computation as the evaluation of mathematical
functions and avoids changing-state and mutable data.”—Wikipedia
• Basic fundamental is to evaluate an expression and use its result for some
other expression
• Made up of function that always return a value
• No side effects state does not change
• Immutable data: cannot change the value once set;no need to lock the
access of shared data
• Reuse same code in different parts of program
• Free order of code execution
6
What is FP in Scala like?
• Supports mutable and immutable data
• Consists of variables and values
• Pass functions as arguments
• Return functions as results from functions
• Define functions inside other function
• Store functions in variables
• Functions are fist class values just like integer
or string
7
Syntax
• No semicolons
• No datatype specification required explicitly,
compiler will determine from context
• Variable definitions start with “var” and
definitions of values (i.e. read only variables)
start with “val”. Val is immutable where var is
mutable
8
Comparison with Java
• Compatible with existing java programs and
we can use all java libraries
• Operates similar to Java. Its compiler
generates byte code that is similar to java
bytecode
• Runs on Eclipse,IntelliJ and Netbeans just as
Java
• Only two things in Scala that are absent in
Java are richer type systems and Functional
programming
9
Using Scala REPL
• REPL-> Read,Eval,Print,Loop
10
Examples for..
• Defining variables
• String, ints
• Non-numeric types
• Tuples
• Expressions and conditions
• Match expression
• Loops
• Defining functions
11
Why Scala?
• Since Scala compiles to Java bytecode and runs on the
JVM, programs written in Scala can benefit from the huge
amount of library code already written in Java. However, by
using Scala you get the following benefits:
– Mandatory boilerplate code is gone – no getters and setters, no
checked exceptions.
– More powerful constructs, that allow you to do more with less
code, such as case classes, option and tuples.
– More powerful code reuse – the elements of code that you can
reuse are smaller. Rather than classes with single inheritance,
you have traits and functions.
http://hedleyproctor.com/2012/04/why-java-developers-should-be-
learning-scala/
12
A typical Java class vs. Scala class
example
• Java class
Class Person {
Private String name;
Private int age;
Person(String name,int age) {
this.name = name;
this.age = age;
}
Public void setAge(int age) {
this.age = age;
}
Public void setName(String name) {
this.name = name;
}
Public int getAge() {
Return this.age;
}
Public String getName() {
return this.name;
}
}
• Scala class
Public class Person {
Var Name = “”
Private Var theAge = 0
Def age = theAge
Def age_= (newAge: Integer): Unit = {if(newAge > 0) theAge = newAge}
}
13
Why Scala contd…
• Scala is compatible
• Scala is concise
• Scala is high level
• Scala is statically typed
14
Scala features in Java8
• Lambda expressions
• Higher order functions
• Parallel collections
• Function chaining
www.infoq.com/articles/java-8-vs-scala
15
Lambda Expressions
• Function literal
• A function with input parameters and function
body
• (type parameter)-> function body
• Eg: (String s1,String s2) -> s1.length() –
s2.length()
16
Limitations
• Syntax
Eg: val <identifier>[: <type>] = <data>
Val name :String = “foo”
Difficult to understand as reading backwards. The return
value is at the end of the declaration,and the type comes
after the name.
• Slow compilation and interpreter
Takes much time to compile and run.We can now use the
FSC (Fast Scala compiler),which essentially stays in
memory.
• Steep learning curve
17
Education
• Programming Scala
• Programming in Scala
• Why Scala?
• Scala Language Specification
18
Tools
• IDEs:NetBeans,Eclipse,IDEA
• Editors: Emacs,VIM,TextMate
19
Questions?
• Def ? = ???
20
Homework
• In the Scala REPL, convert the temperature value of 22.5 Centigrade to Fahrenheit. The conversion formula
is cToF(x) = (x * 9/5) + 32.
• Write a new centigrade-to-fahrenheit conversion (using the formula (x * 9/5) + 32), saving each step of the
conversion into separate values. What do you expect the type of each value will be?
• Using the input string "Frank,123 Main,925-555-1943,95122" and regular expression matching, retrieve the
telephone number. Can you convert each part of the telephone number to its own integer value? How would
you store this in a tuple?
• There is a popular coding interview question I’ll call "typesafe", in which the numbers 1 - 100 must be
printed one per line. The catch is that multiples of 3 must replace the number with the word "type", while
multiples of 5 must replace the number with the word "safe". Of course, multiples of 15 must print
"typesafe".
21

Más contenido relacionado

La actualidad más candente

Functional OOP, Clojure style
Functional OOP, Clojure styleFunctional OOP, Clojure style
Functional OOP, Clojure styleyoavrubin
 
Java 201 Intro to Test Driven Development in Java
Java 201   Intro to Test Driven Development in JavaJava 201   Intro to Test Driven Development in Java
Java 201 Intro to Test Driven Development in Javaagorolabs
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLsIndicThreads
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuSrimanta Sahu
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in ScalaAbhijit Sharma
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercisesagorolabs
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03) Jonathan Engelsma
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programmingagorolabs
 
Responsive Facets with Apache Solr
Responsive Facets with Apache SolrResponsive Facets with Apache Solr
Responsive Facets with Apache SolrBrent Lemons
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) Jonathan Engelsma
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaSynesso
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 

La actualidad más candente (14)

Functional OOP, Clojure style
Functional OOP, Clojure styleFunctional OOP, Clojure style
Functional OOP, Clojure style
 
Java 201 Intro to Test Driven Development in Java
Java 201   Intro to Test Driven Development in JavaJava 201   Intro to Test Driven Development in Java
Java 201 Intro to Test Driven Development in Java
 
Scala
ScalaScala
Scala
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLs
 
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_SahuA-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
A-Brief-Introduction-To-JAVA8_By_Srimanta_Sahu
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
 
05 functional programming
05 functional programming05 functional programming
05 functional programming
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercises
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 03)
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
Responsive Facets with Apache Solr
Responsive Facets with Apache SolrResponsive Facets with Apache Solr
Responsive Facets with Apache Solr
 
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02) iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 

Destacado

Distributed machine learning 101 using apache spark from the browser
Distributed machine learning 101 using apache spark from the browserDistributed machine learning 101 using apache spark from the browser
Distributed machine learning 101 using apache spark from the browserAndy Petrella
 
Scala for Machine Learning
Scala for Machine LearningScala for Machine Learning
Scala for Machine LearningPatrick Nicolas
 
Understanding Hadoop Clusters and the Network
Understanding Hadoop Clusters and the NetworkUnderstanding Hadoop Clusters and the Network
Understanding Hadoop Clusters and the Networkbradhedlund
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"Kazuhiro Sera
 
Why is Bioinformatics a Good Fit for Spark?
Why is Bioinformatics a Good Fit for Spark?Why is Bioinformatics a Good Fit for Spark?
Why is Bioinformatics a Good Fit for Spark?Timothy Danford
 
Java/Scala Lab 2016. Александр Конопко: Машинное обучение в Spark.
Java/Scala Lab 2016. Александр Конопко: Машинное обучение в Spark.Java/Scala Lab 2016. Александр Конопко: Машинное обучение в Spark.
Java/Scala Lab 2016. Александр Конопко: Машинное обучение в Spark.GeeksLab Odessa
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInVitaly Gordon
 
Using Deep Learning for Recommendation
Using Deep Learning for RecommendationUsing Deep Learning for Recommendation
Using Deep Learning for RecommendationEduardo Gonzalez
 
Getting Started with Deep Learning using Scala
Getting Started with Deep Learning using ScalaGetting Started with Deep Learning using Scala
Getting Started with Deep Learning using ScalaTaisuke Oe
 
PredictionIO – A Machine Learning Server in Scala – SF Scala
PredictionIO – A Machine Learning Server in Scala – SF ScalaPredictionIO – A Machine Learning Server in Scala – SF Scala
PredictionIO – A Machine Learning Server in Scala – SF Scalapredictionio
 
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...Jose Quesada (hiring)
 
Machine Learning with Scala
Machine Learning with ScalaMachine Learning with Scala
Machine Learning with ScalaSusan Eraly
 
Large-Scale Machine Learning with Apache Spark
Large-Scale Machine Learning with Apache SparkLarge-Scale Machine Learning with Apache Spark
Large-Scale Machine Learning with Apache SparkDB Tsai
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkRahul Jain
 

Destacado (14)

Distributed machine learning 101 using apache spark from the browser
Distributed machine learning 101 using apache spark from the browserDistributed machine learning 101 using apache spark from the browser
Distributed machine learning 101 using apache spark from the browser
 
Scala for Machine Learning
Scala for Machine LearningScala for Machine Learning
Scala for Machine Learning
 
Understanding Hadoop Clusters and the Network
Understanding Hadoop Clusters and the NetworkUnderstanding Hadoop Clusters and the Network
Understanding Hadoop Clusters and the Network
 
Learning from "Effective Scala"
Learning from "Effective Scala"Learning from "Effective Scala"
Learning from "Effective Scala"
 
Why is Bioinformatics a Good Fit for Spark?
Why is Bioinformatics a Good Fit for Spark?Why is Bioinformatics a Good Fit for Spark?
Why is Bioinformatics a Good Fit for Spark?
 
Java/Scala Lab 2016. Александр Конопко: Машинное обучение в Spark.
Java/Scala Lab 2016. Александр Конопко: Машинное обучение в Spark.Java/Scala Lab 2016. Александр Конопко: Машинное обучение в Spark.
Java/Scala Lab 2016. Александр Конопко: Машинное обучение в Spark.
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
Using Deep Learning for Recommendation
Using Deep Learning for RecommendationUsing Deep Learning for Recommendation
Using Deep Learning for Recommendation
 
Getting Started with Deep Learning using Scala
Getting Started with Deep Learning using ScalaGetting Started with Deep Learning using Scala
Getting Started with Deep Learning using Scala
 
PredictionIO – A Machine Learning Server in Scala – SF Scala
PredictionIO – A Machine Learning Server in Scala – SF ScalaPredictionIO – A Machine Learning Server in Scala – SF Scala
PredictionIO – A Machine Learning Server in Scala – SF Scala
 
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
 
Machine Learning with Scala
Machine Learning with ScalaMachine Learning with Scala
Machine Learning with Scala
 
Large-Scale Machine Learning with Apache Spark
Large-Scale Machine Learning with Apache SparkLarge-Scale Machine Learning with Apache Spark
Large-Scale Machine Learning with Apache Spark
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache Spark
 

Similar a Scala-Ls1

Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala languageAaqib Pervaiz
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumNgoc Dao
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark Summit
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNManish Pandit
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageAzilen Technologies Pvt. Ltd.
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 

Similar a Scala-Ls1 (20)

Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala language
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Unit 1
Unit 1Unit 1
Unit 1
 
Java9to19Final.pptx
Java9to19Final.pptxJava9to19Final.pptx
Java9to19Final.pptx
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
 
Yes scala can!
Yes scala can!Yes scala can!
Yes scala can!
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Developer’s viewpoint on swift programming language
Developer’s viewpoint on swift programming languageDeveloper’s viewpoint on swift programming language
Developer’s viewpoint on swift programming language
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 

Scala-Ls1

  • 2. What is Scala? • Scala(ska-lah) stands for Scalable Language • Combines functional programming with Object Oriented Programming • Growing as per the demand of the users • Write small scripts as well as build larger systems 2
  • 3. What is Scala? Contd. • Runs on the java platform(Java Virtual Machine) as well as Dot net platform • Designed by Martin Odersky in 2001 at EPFL, who was also one of the creators of javac compiler and generic java • Open source • Released in 2004 • Second version v 2.0 in 2006 • Current version 2.11.5 3
  • 4. What makes Scala scalable? • Combining OOP with functional programming 4
  • 5. Why OOP? • Purely OO • Every operation is method • Every value is an object • No primitive types, everything is an object • 1+2 invokes a method + defined in the class Int 5
  • 6. What is Functional Programming(FP)? • “In computer science, functional programming is a programming paradigm, a style of building the structure and elements of computer programs, that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.”—Wikipedia • Basic fundamental is to evaluate an expression and use its result for some other expression • Made up of function that always return a value • No side effects state does not change • Immutable data: cannot change the value once set;no need to lock the access of shared data • Reuse same code in different parts of program • Free order of code execution 6
  • 7. What is FP in Scala like? • Supports mutable and immutable data • Consists of variables and values • Pass functions as arguments • Return functions as results from functions • Define functions inside other function • Store functions in variables • Functions are fist class values just like integer or string 7
  • 8. Syntax • No semicolons • No datatype specification required explicitly, compiler will determine from context • Variable definitions start with “var” and definitions of values (i.e. read only variables) start with “val”. Val is immutable where var is mutable 8
  • 9. Comparison with Java • Compatible with existing java programs and we can use all java libraries • Operates similar to Java. Its compiler generates byte code that is similar to java bytecode • Runs on Eclipse,IntelliJ and Netbeans just as Java • Only two things in Scala that are absent in Java are richer type systems and Functional programming 9
  • 10. Using Scala REPL • REPL-> Read,Eval,Print,Loop 10
  • 11. Examples for.. • Defining variables • String, ints • Non-numeric types • Tuples • Expressions and conditions • Match expression • Loops • Defining functions 11
  • 12. Why Scala? • Since Scala compiles to Java bytecode and runs on the JVM, programs written in Scala can benefit from the huge amount of library code already written in Java. However, by using Scala you get the following benefits: – Mandatory boilerplate code is gone – no getters and setters, no checked exceptions. – More powerful constructs, that allow you to do more with less code, such as case classes, option and tuples. – More powerful code reuse – the elements of code that you can reuse are smaller. Rather than classes with single inheritance, you have traits and functions. http://hedleyproctor.com/2012/04/why-java-developers-should-be- learning-scala/ 12
  • 13. A typical Java class vs. Scala class example • Java class Class Person { Private String name; Private int age; Person(String name,int age) { this.name = name; this.age = age; } Public void setAge(int age) { this.age = age; } Public void setName(String name) { this.name = name; } Public int getAge() { Return this.age; } Public String getName() { return this.name; } } • Scala class Public class Person { Var Name = “” Private Var theAge = 0 Def age = theAge Def age_= (newAge: Integer): Unit = {if(newAge > 0) theAge = newAge} } 13
  • 14. Why Scala contd… • Scala is compatible • Scala is concise • Scala is high level • Scala is statically typed 14
  • 15. Scala features in Java8 • Lambda expressions • Higher order functions • Parallel collections • Function chaining www.infoq.com/articles/java-8-vs-scala 15
  • 16. Lambda Expressions • Function literal • A function with input parameters and function body • (type parameter)-> function body • Eg: (String s1,String s2) -> s1.length() – s2.length() 16
  • 17. Limitations • Syntax Eg: val <identifier>[: <type>] = <data> Val name :String = “foo” Difficult to understand as reading backwards. The return value is at the end of the declaration,and the type comes after the name. • Slow compilation and interpreter Takes much time to compile and run.We can now use the FSC (Fast Scala compiler),which essentially stays in memory. • Steep learning curve 17
  • 18. Education • Programming Scala • Programming in Scala • Why Scala? • Scala Language Specification 18
  • 21. Homework • In the Scala REPL, convert the temperature value of 22.5 Centigrade to Fahrenheit. The conversion formula is cToF(x) = (x * 9/5) + 32. • Write a new centigrade-to-fahrenheit conversion (using the formula (x * 9/5) + 32), saving each step of the conversion into separate values. What do you expect the type of each value will be? • Using the input string "Frank,123 Main,925-555-1943,95122" and regular expression matching, retrieve the telephone number. Can you convert each part of the telephone number to its own integer value? How would you store this in a tuple? • There is a popular coding interview question I’ll call "typesafe", in which the numbers 1 - 100 must be printed one per line. The catch is that multiples of 3 must replace the number with the word "type", while multiples of 5 must replace the number with the word "safe". Of course, multiples of 15 must print "typesafe". 21

Notas del editor

  1. Its object-oriented constructs make it easy to structure larger systems and to adapt them to new demands. The combination of both styles in Scala makes it possible to express new kinds of programming patterns and component abstractions. It also leads to a legible and concise programming style.
  2. Scala heavily reuses Java, it allows you to add value to existing code since it designed to work seamlessly with Java Scala code can call Java methods, access Java fields inherit Java classes, and implement Java interfaces - Scala is quicker to write, easier to read, most importantly less error prone than java No need to repetitively provide types to the variables,Scala’s type inference is a major contributor to Scala’s conciseness Scala helps you manage complexity by letting you raise the level of ab- straction in the interfaces you design and use. A static type system classifies variables and expressions according to the kinds of values they hold and compute. it addresses nicely two of the usual concerns about static typing: verbosity is avoided through type inference and flexibility is gained through pattern matching and several new ways to write and compose types. With these impediments out of the way, the classical benefits of static type systems can be better appreciated.