SlideShare une entreprise Scribd logo
1  sur  12
Scala workshop
If I were to pick a language to use today
     other than Java, it would be Scala.

             James Gosling
Scala, it must be stated, is the current heir
apparent to the Java throne. No other language
   on the JVM seems as capable of being a
   "replacement for Java" as Scala, and the
momentum behind Scala is now unquestionable.

      Charlies Olivier Nutter - JRuby lead
Though my tip though for the long term
  replacement of javac is Scala. I'm very
   impressed with it! I can honestly say if
someone had shown me the Programming
 in Scala book by by Martin Odersky, Lex
   Spoon & Bill Venners back in 2003 I'd
    probably have never created Groovy.

             James Strachen
public class Person {
      private int age;
      private String name;

        public Person(int age, String name) {
          this.age = age;
          this.name = name;
        }

        public int getAge() {
          return this.age;
        }

        public void setAge(int age) {
          this.age = age;
        }

        public String getName() {
          return this.name;
        }

        public void setName(String name) {
          this.name = name;
        }
    }




class Person(var age: Int, var name: String)
List<Person> persons = ...
List<Person> adults = new LinkedList<Person>();
List<Person> kids = new LinkedList<Person>();
for (Person person : persons) {
  if (person.getAge() < 18) {
    kids.add(person);
  } else {
    adults.add(person);
  }
}




val (kids, adults) = persons.partition(_.age < 18)
String s = "!em esreveR";
System.out.println(s.reverse());




val s: java.lang.String = "!em esreveR"
println(s.reverse)

=> Reverse me!
BufferedReader reader = null;
try {
  reader = new BufferedReader(new FileReader("f.txt"));
  System.out.println(reader.readLine());
} finally {
  if (reader != null) {
    try {
      reader.close();
    } catch (IOException e) {
      // Exception on close, ignore
    }
  }
}




using(new BufferedReader(new FileReader("f.txt"))) {
    reader => println(reader.readLine())
}
I will never forget these words: "With great power
  comes great responsibility." This is my gift, my
         curse. Who am I? I'm Spider-man.
val myList = List(1, 2, 3)
val res = (10/:myList)(_+_)


??
Scala
●   Object oriented and functional
●   Statically typed
●   Java compatible
    ●   Complies to Java bytecode (and CLR)
    ●   Existing libraries/frameworks
●   Better Java
Todays schedule
●   Basic syntax
●   REPL, IDEs and setup
●   First class functions
●   Pattern matching
●   OO and traits
●   Functional programming
●   ++

Contenu connexe

Similaire à 1.1 motivation

Scala == Effective Java
Scala == Effective JavaScala == Effective Java
Scala == Effective JavaScalac
 
Intro to scala
Intro to scalaIntro to scala
Intro to scalaJoe Zulli
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Jesper Kamstrup Linnet
 
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 WorldBTI360
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaDerek Chen-Becker
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)William Narmontas
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)HamletDRC
 
Scala for Java Developers (Silicon Valley Code Camp 13)
Scala for Java Developers (Silicon Valley Code Camp 13)Scala for Java Developers (Silicon Valley Code Camp 13)
Scala for Java Developers (Silicon Valley Code Camp 13)Ramnivas Laddad
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basicswpgreenway
 

Similaire à 1.1 motivation (20)

1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
 
1.1 motivation
1.1 motivation1.1 motivation
1.1 motivation
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
Scala == Effective Java
Scala == Effective JavaScala == Effective Java
Scala == Effective Java
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
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
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala
ScalaScala
Scala
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Scala for Java Developers (Silicon Valley Code Camp 13)
Scala for Java Developers (Silicon Valley Code Camp 13)Scala for Java Developers (Silicon Valley Code Camp 13)
Scala for Java Developers (Silicon Valley Code Camp 13)
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 

1.1 motivation

  • 2. If I were to pick a language to use today other than Java, it would be Scala. James Gosling
  • 3. Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable of being a "replacement for Java" as Scala, and the momentum behind Scala is now unquestionable. Charlies Olivier Nutter - JRuby lead
  • 4. Though my tip though for the long term replacement of javac is Scala. I'm very impressed with it! I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy. James Strachen
  • 5. public class Person { private int age; private String name; public Person(int age, String name) { this.age = age; this.name = name; } public int getAge() { return this.age; } public void setAge(int age) { this.age = age; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } } class Person(var age: Int, var name: String)
  • 6. List<Person> persons = ... List<Person> adults = new LinkedList<Person>(); List<Person> kids = new LinkedList<Person>(); for (Person person : persons) { if (person.getAge() < 18) { kids.add(person); } else { adults.add(person); } } val (kids, adults) = persons.partition(_.age < 18)
  • 7. String s = "!em esreveR"; System.out.println(s.reverse()); val s: java.lang.String = "!em esreveR" println(s.reverse) => Reverse me!
  • 8. BufferedReader reader = null; try { reader = new BufferedReader(new FileReader("f.txt")); System.out.println(reader.readLine()); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { // Exception on close, ignore } } } using(new BufferedReader(new FileReader("f.txt"))) { reader => println(reader.readLine()) }
  • 9. I will never forget these words: "With great power comes great responsibility." This is my gift, my curse. Who am I? I'm Spider-man.
  • 10. val myList = List(1, 2, 3) val res = (10/:myList)(_+_) ??
  • 11. Scala ● Object oriented and functional ● Statically typed ● Java compatible ● Complies to Java bytecode (and CLR) ● Existing libraries/frameworks ● Better Java
  • 12. Todays schedule ● Basic syntax ● REPL, IDEs and setup ● First class functions ● Pattern matching ● OO and traits ● Functional programming ● ++