Your SlideShare is downloading. ×
0
Why Scala?
Why Scala?
Why Scala?
Why Scala?
Why Scala?
Why Scala?
Why Scala?
Why Scala?
Why Scala?
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Why Scala?

1,774

Published 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.

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,774
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
45
Comments
0
Likes
1
Embeds 0
No embeds

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? <ul><li>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. </li></ul><ul><li>-- Martin Odersky </li></ul><ul><li>Huh? </li></ul><ul><li>-- Fogus </li></ul>
  • 3. Let's Create a Map! <ul><li>Java </li></ul><ul><li>Scala </li></ul>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 <ul><li>public class Person </li></ul><ul><li>{ </li></ul><ul><li>private String lastName; </li></ul><ul><li>private String firstName; </li></ul><ul><li>private Person spouse; </li></ul><ul><li>public Person(String fn, String ln, Person s) { </li></ul><ul><li>lastName = ln; </li></ul><ul><li>firstName = fn; </li></ul><ul><li>spouse = s; </li></ul><ul><li>} </li></ul><ul><li>public Person(String fn, String ln) { </li></ul><ul><li>this(fn, ln, null); </li></ul><ul><li>} </li></ul><ul><li>public String getFirstName() { return firstName; } </li></ul><ul><li>public String getLastName() { return lastName; } </li></ul><ul><li>public Person getSpouse() { return spouse; } </li></ul><ul><li>public void setSpouse(Person p) { spouse = p; } </li></ul><ul><li>public String introduction() { </li></ul><ul><li>return &quot;Hi, my name is &quot; + firstName + &quot; &quot; + lastName + </li></ul><ul><li>(spouse != null ? </li></ul><ul><li>&quot; and this is my spouse, &quot; + spouse.firstName + &quot; &quot; + spouse.lastName + &quot;.&quot; : </li></ul><ul><li>&quot;.&quot;); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  • 5. No Boilerplate <ul><li>class Person(val lastName:String, val firstName:String, val spouse:Option[Person]) { </li></ul><ul><li>def this(ln:String, fn:String) = this(ln, fn, None) </li></ul><ul><li>def intro():String = </li></ul><ul><li>(spouse match { </li></ul><ul><li>case None => &quot;.&quot; </li></ul><ul><li>case Some(s) => &quot; and this is my spouse, &quot; + s.firstName + &quot; &quot; + s.lastName + &quot;.&quot; </li></ul><ul><li>}); </li></ul><ul><li>} </li></ul>By default , Scala classes are immutable.
  • 6. Concurrency <ul><li>Actors </li></ul><ul><ul><li>Send a finite number of messages to other actors </li></ul></ul><ul><ul><ul><li>No shared state </li></ul></ul></ul><ul><ul><li>Create a finite number of new actors </li></ul></ul><ul><ul><li>Designate the behavior to be used for the next message it receives </li></ul></ul><ul><ul><ul><li>Event driven </li></ul></ul></ul>
  • 7. Misc. <ul><ul><li>You can embed XML directly into Scala clauses </li></ul></ul><ul><ul><li>Functional programming </li></ul></ul><ul><ul><li>Everything is an object </li></ul></ul><ul><ul><li>List comprehensions </li></ul></ul><ul><ul><li>Case classes </li></ul></ul><ul><ul><li>Pattern Matching </li></ul></ul>
  • 8. Why Not Java? <ul><li>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. </li></ul>
  • 9. L@@k <ul><li>http://scala-lang.org </li></ul><ul><li>http://www.artima.com/weblogs/index.jsp?blogger=modersky </li></ul><ul><li>http://ola-bini.blogspot.com/search/label/scala </li></ul><ul><li>http://www.drmaciver.com/planetscala/ </li></ul><ul><li>http://lambda-the-ultimate.org/search/node/Scala </li></ul><ul><li>#scala </li></ul>

×