Why Scala?
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Why Scala?

  • 2,457 views
Uploaded on

A short presentation given at my workplace introducing the Scala programming language.

A short presentation given at my workplace introducing the Scala programming language.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,457
On Slideshare
2,409
From Embeds
48
Number of Embeds
5

Actions

Shares
Downloads
42
Comments
0
Likes
1

Embeds 48

http://www.linkedin.com 18
https://www.linkedin.com 16
http://dschool.co 7
http://www.slideshare.net 6
http://www.lmodules.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Why Scala? (or why not Java?)
  • 2. What is Scala?
    • Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages. It is also fully interoperable with Java.
    • -- Martin Odersky
    • Huh?
    • -- Fogus
  • 3. Let's Create a Map!
    • Java
    • Scala
    Map<String, Integer> numMap = new HashMap<String, Integer>(); numMap.put(&quot;one&quot;, 1); numMap.put(&quot;two&quot;, 2); nummap.put(&quot;three&quot;, 3); var numMap = Map(&quot;one&quot; -> 1, &quot;two&quot; -> 2, &quot;three&quot; -> 3) These are equivalent constructs and will work identically thanks to type-inference. Hooray for compile-time type checking and succinctness!
  • 4. Boilerplate
    • public class Person
    • {
    • private String lastName;
    • private String firstName;
    • private Person spouse;
    • public Person(String fn, String ln, Person s) {
    • lastName = ln;
    • firstName = fn;
    • spouse = s;
    • }
    • public Person(String fn, String ln) {
    • this(fn, ln, null);
    • }
    • public String getFirstName() { return firstName; }
    • public String getLastName() { return lastName; }
    • public Person getSpouse() { return spouse; }
    • public void setSpouse(Person p) { spouse = p; }
    • public String introduction() {
    • return &quot;Hi, my name is &quot; + firstName + &quot; &quot; + lastName +
    • (spouse != null ?
    • &quot; and this is my spouse, &quot; + spouse.firstName + &quot; &quot; + spouse.lastName + &quot;.&quot; :
    • &quot;.&quot;);
    • }
    • }
  • 5. No Boilerplate
    • class Person(val lastName:String, val firstName:String, val spouse:Option[Person]) {
    • def this(ln:String, fn:String) = this(ln, fn, None)
    • def intro():String =
    • (spouse match {
    • case None => &quot;.&quot;
    • case Some(s) => &quot; and this is my spouse, &quot; + s.firstName + &quot; &quot; + s.lastName + &quot;.&quot;
    • });
    • }
    By default , Scala classes are immutable.
  • 6. Concurrency
    • Actors
      • Send a finite number of messages to other actors
        • No shared state
      • Create a finite number of new actors
      • Designate the behavior to be used for the next message it receives
        • Event driven
  • 7. Misc.
      • You can embed XML directly into Scala clauses
      • Functional programming
      • Everything is an object
      • List comprehensions
      • Case classes
      • Pattern Matching
  • 8. Why Not Java?
    • Actually, we will use Java extensively as every Java class can be seamlessly integrated into Scala. However, we will leverage the advantages that Scala provides.
  • 9. L@@k
    • http://scala-lang.org
    • http://www.artima.com/weblogs/index.jsp?blogger=modersky
    • http://ola-bini.blogspot.com/search/label/scala
    • http://www.drmaciver.com/planetscala/
    • http://lambda-the-ultimate.org/search/node/Scala
    • #scala