1 / 14

The Scala Programming Language

The Scala Programming Language. John Benton Miguel Contreras Bobby Frankenberger. The Father of Scala. Design of Scala started in 2001 at the École Polytechnique Fédérale de Lausanne (EPFL) by Martin Odersky . Overview of Relevant Paradigm.

adelle
Download Presentation

The Scala Programming Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Scala Programming Language John Benton Miguel Contreras Bobby Frankenberger

  2. The Father of Scala • Design of Scala started in 2001 at the École Polytechnique Fédérale de Lausanne (EPFL) by Martin Odersky.

  3. Overview of Relevant Paradigm • Scala is a multi-paradigm programming language. • Runs on the standard Java and .NET platforms • Interoperates seamlessly with all Java libraries

  4. Multi-paradigm • Integrates features of functional and object-oriented languages • The two programming styles are complementary

  5. Multi-paradigm Object-Oriented Paradigm Functional Paradigm Every function is a value. Lightweight syntax for defining anonymous functions. Higher-order functions Sequence comprehensions Pattern matching • Every value is an object • Types and behavior of objects are described by classes and traits • Class abstractions are extended by subclassing and mixin-based composition mechanism

  6. Seamless Integration with Java • Existing Java code and programming skills are fully re-usable • Can make full use of existing Java libraries or application code • Scala programs run on Java VM and are byte code compatible with Java • Scala can be called from Java, and Java can be called from Scala

  7. Why Scala? • Scala programming language designed to be a “better Java” • Design objectives were to clean up what are often considered poor design decisions in Java. • E.g., Type erasure, checked exceptions, and the non-unified type system. • Allow cleaner, more concise, and more expressive code to be written

  8. Interesting / Core Concepts • Syntactic Flexibility • FOR-Comprehensions • Unified Type System

  9. Syntactic Flexibility • Semicolons unnecessary. Lines auto-joined if they begin or end with an inappropriate token. • Methods used as infix operators: • Object.method(arg) = Object method arg • Operators are treated like methods. • Parentheses can be excluded completely if function takes no arg.

  10. FOR-Comprehensions • A powerful extension of “foreach”. Similar to list comprehensions. • Generates a new collection of objects by iterating over an existing collection and mapping those objects to the new collection via some function. val s = for(x <- 1 to 20if x*x > 50)yield2*x -returns- Vector(16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40)

  11. Unified Type System • No distinction between primitive vs. reference types • All types are inherited from the top-level class Any • No confusing distinctions b/w int and Integer • No static type. Uses singleton objects instead. • Default visibility is public.

  12. What does Scala look like? • Object defHelloWorld { • def main(args: Array(String) { • println(“Hello world!”) • } • } Scala Hello World! class HelloWorldApp{ public static void main(String[] args) { System.out.println("Hello World!"); } } Java Hello World!

  13. What does Scala look like? • object primes extends Application { • defisPrime(n: Int) = (2 until n) forall(n % _ != 0) • for(i <- 1 to 100 ifisPrime(i)) println(i) • } Scala Primes void primes() { for ( inti = 2; i < 100; i++){ booleanisPrime= true; for( intj = 3; j*j <= i; j+=2) { if( i % j == 0) isPrime = false; } if (isPrime) System.out.println(N); } } Java Primes

  14. References • Scala Code: http://www.scala-lang.org • Java Hello World: http://docs.oracle.com/javase/tutorial/index.html • Java Primes: badly written by Miguel Contreras

More Related