Your SlideShare is downloading. ×
0
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
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

On Scala Slides - OSDC 2009

1,394

Published on

A presentation by Tom Lee and Michael Neale at OSDC conference, Brisbane, 2009. Why scala sucks less.

A presentation by Tom Lee and Michael Neale at OSDC conference, Brisbane, 2009. Why scala sucks less.

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,394
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
37
Comments
0
Likes
2
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. On Scala Or: Why Static Typing Doesn't Have to Suck
  • 2. Your Designated Presenter Units <ul><li>Michael Neale </li></ul><ul><li>  </li></ul><ul><ul><li>Employed by Red Hat </li></ul></ul><ul><ul><ul><li>Works on various jboss projects </li></ul></ul></ul><ul><ul><ul><li>Talks a lot </li></ul></ul></ul><ul><ul><li>Developer behind Drools </li></ul></ul><ul><li>  </li></ul><ul><li>Thomas Lee </li></ul><ul><li>  </li></ul><ul><ul><li>Works for Shine Technologies </li></ul></ul><ul><ul><ul><li>Groundskeeper </li></ul></ul></ul><ul><ul><li>Sporadic open source contributor guy </li></ul></ul>
  • 3. On Java ...
  • 4. The Language Is Like, So 1991
  • 5. But The VM is Okay
  • 6. And there are libraries for everything
  • 7. On Scala ...
  • 8. What We Want To Say <ul><li>&quot;I want a mapping of String keys to Integer values&quot; </li></ul>
  • 9. What We Have To Say in Java <ul><li>HashMap<String, Integer> map = new HashMap<String, Integer>(); </li></ul>
  • 10. What We Can Say in Scala <ul><li>val map = new HashMap[String, Int] </li></ul>
  • 11. What we want to say &quot;I want stuff to happen when the user click a button&quot;
  • 12. What we have to say in Java <ul><li>import javax.swing.JButton; </li></ul><ul><li>import java.awt.event.ActionListener </li></ul><ul><li>import java.awt.event.ActionEvent </li></ul><ul><li>JButton button = new JButton(&quot;Click Me!&quot;); </li></ul><ul><li>button.addActionListener( new ActionListener(){ </li></ul><ul><li>  public void actionPerformed(ActionEvent e) { </li></ul><ul><li>    // stuff(); </li></ul><ul><li>  } </li></ul><ul><li>}); </li></ul>
  • 13. What we can say in Scala <ul><li>import scala.swing.Button </li></ul><ul><li>import scala.swing.events.ButtonClicked </li></ul><ul><li>  </li></ul><ul><li>val button = new Button(&quot;Click Me!&quot;) </li></ul><ul><li>button.reactions += { </li></ul><ul><li>    case ButtonClicked(e) => // stuff() </li></ul><ul><li>} </li></ul>
  • 14. But what about Ruby/Python/Perl?!!1!
  • 15. Scala types are statically checked
  • 16. Sun JVM: no GIL / green threads / etc.
  • 17. But Scala is comparably expressive
  • 18. An example: Ruby and Scala <ul><li>&quot;Both a house and a car can be sold, but are not related.&quot; </li></ul>
  • 19. What we say in Ruby <ul><li>class House; def value; 400000; end ; end </li></ul><ul><li>class Car; def value; 30000; end ; end </li></ul><ul><li>class BankAccount </li></ul><ul><li>  def initialize(balance); @balance = balance; end </li></ul><ul><li>  def credit(amount); @balance += amount; end </li></ul><ul><li>end </li></ul><ul><li>  </li></ul><ul><li>def sell(acct, asset); acct.credit(asset.value); end </li></ul><ul><li>bank_acct = BankAccount.new(0) </li></ul><ul><li>sell(bank_acct, House.new) </li></ul><ul><li>sell(bank_acct, Car.new) </li></ul>
  • 20. What we say in Scala <ul><li>class House { def value = 400000 } class Car { def value = 30000 } class BankAccount( var balance : Int)   def credit(balance : Int) = </li></ul><ul><li>    this .balance += balance } object BankApp extends Application {   def sell(acct:BankAccount, asset:{ def value : Int}) =     acct.credit(asset.value)   val bankAcct = new BankAccount(0)   sell(bankAcct, new House)   sell(bankAcct, new Car) } </li></ul>
  • 21. The best of both worlds?
  • 22. Other cool Scala stuff
  • 23. Actors for concurrency <ul><li>val actor = actor { loop { receive { </li></ul><ul><li>   case Message(m) => ... </li></ul><ul><li>   case Another(m) => reply { answer } </li></ul><ul><li>}}} </li></ul><ul><li>actor ! Message(&quot;hello&quot;) </li></ul><ul><li>val answer = actor !? Another(&quot;ola&quot;) </li></ul><ul><li>//its just a library ! other options: STM etc... </li></ul>
  • 24. Actors for concurrency
  • 25. Pattern matching <ul><li>val v = something match { </li></ul><ul><li>   case Something(s) => whatever(s) </li></ul><ul><li>   case m: SomeClass => whatever(m) </li></ul><ul><li>   case (42, &quot;hey&quot;) => 42 </li></ul><ul><li>   case _ => &quot;Nothing matched&quot; </li></ul><ul><li>} </li></ul><ul><li>//compiler can warn for non exhaustive match </li></ul>
  • 26. Pattern matching
  • 27. Implicits <ul><li>implicit def extendClass(c: LegacyClass) = EnhancedClass(c) </li></ul><ul><li>//demo ! </li></ul><ul><li>//used to enhance stuff </li></ul><ul><li>//use wisely ! </li></ul>
  • 28. Functional Programming <ul><li>closures/lambdas  </li></ul><ul><li>(i: Int, s: String) => println(s + (i + 1)) </li></ul><ul><li>val func = (i : Int) => ....  </li></ul><ul><li>val nums = (1 to 100) filter (_ < 50) </li></ul><ul><li>def log(message: => String) = .... </li></ul><ul><li>val immutableList = List(1, 2, 3) </li></ul><ul><li>def calcSomething : Option[Result] = ... </li></ul><ul><li>calcSomething match { case Result => ... } //no NPE ! </li></ul>
  • 29. Functional Programming <ul><ul><li>fold* </li></ul></ul><ul><ul><li>map </li></ul></ul><ul><ul><li>filter </li></ul></ul><ul><ul><li>lazy sequences </li></ul></ul>
  • 30. Functional Programming
  • 31. Dynamic language-like? <ul><li>Duck typing => Structural typing </li></ul><ul><li>Monkey patching => Implicit methods </li></ul><ul><li>A shell ! </li></ul>
  • 32. Who is using it?  <ul><ul><li>Twitter </li></ul></ul><ul><ul><li>Foursquare </li></ul></ul><ul><ul><li>EDF Trading </li></ul></ul><ul><ul><li>Siemens </li></ul></ul><ul><ul><li>... and others! </li></ul></ul>
  • 33. Questions?

×