0
Scala – why you
should care
SJUG @ Atlassian HQ, 2009


Michael Neale
JBoss R&D
Red Hat Middleware




                   ...
Michael Neale
R&D w. JBoss (specialise in drools)
Open source history (user -> fulltime
 developer “acquired” by jboss 200...
Outline
 • The elevator pitch
 • Why another language?
 • Scala in more detail
 • Actors/concurrency
 • State of the tools...
Quick intro
• Scala is a OO/FP hybrid language
• Statically strongly typed
• Scala is a compiler + small (ish) rt.jar
• Co...
What's it like to drive




           5
The surface diferences...
public Integer methodName()... public void another(String s)...

def methodName : Integer = {......
final Map<String, Integer> m = new HashMap<String, Integer>();

m.put(“hello”, 42);

m.put(“goodbye”, 42);




val m = Map...
Higher level




      8
9
Closures... fnally
Pascal has them, Even C has them...



    (age: Int) => println(“I am “ + age)



    val fn = (age: I...
Why another language
Java showing its age
Was built in a hurry, unable to shoe-horn
 enough in... (eg. unable to agree on
...
12
But why Scala...
• Why not?
• Valid javac successor (true to the
  intentions of Java, static typed, fast
  etc)
• Designe...
Slightly deeper
• Scala is very deep, but you don't have
  to know that much (unless you are a
  library author, probably)...
15
Just so you know I am not making this up...




                      16
Using java libs..
• Just works
• Arrays in java are “decorated” to be
  like “Lazy sequences”
• (previous slide was JExcel...
Lazyness...
• Hard work pays of eventually
• (but lazyness pays of now)
• Lazy can be GOOD in a language
• “lazy” keyword,...
Dynamic language “magic”


 • Monkey patching → Implicits
 • Duck typing → Structural typing




                   19
Implicits...


.. Is how you “extend” a class
Anywhere “in scope” - called
automagically
With great power comes...
Its com...
Structural typing




         21
Traits...
• Like interfaces, but can have
  implementations in it
• “Mix ins” - compile time or
  construction time
      ...
Pattern matching




        23
Everything is..
• An expression that returns a value
• “Unit” is like Void
• Even if “statements”, pattern matches
  etc.
...
DSL friendly
• Malleable syntax (internal DSLs)
• Parser combinator library (write
  parsers in scala)




               ...
Concurrency




        26
Option/Either
• “Monad” patterns
• Don't have to care, just return option if
  you are not sure if you will have a
  resul...
State of the tools
• IntelliJ demo time...
• Eclipse – well, maybe with 2.8
• Netbeans: Good !
• Emacs/textmate ??
• Maven...
Who is using it ?
• Big Important companies all over...
• Twitter !
• EPFL, Jetbrains etc committed to
  continuing develo...
Some extra magic
• QuickCheck (ScalaCheck)
   – Demo
   –   import org.scalacheck.Prop.forAll

   –   scala> class FeeCalc...
Mixed source...
• Scala compiler can work with mixed
  java and scala source
• (multiple passes) – similar to groovy
• Mea...
Case classes
• Case classes help you out (equals,
   hashCode, pattern matching)
• No “new” needed
• Eg:
case class Car(ty...
Anti static
• No statics in Scala
• But you can swap “class” for “object”
   and its kind of sort of the same (but
   bett...
Resources...
 • scala-lang.org
 • A few good books (Programming In
    Scala) and growing
 • #scala on freenode




      ...
Conclusion...
• Very powerful, mature, fun !
• Would you use it over groovy?
• No “grails” or “rails” (Lift just Ain't It)...
Upcoming SlideShare
Loading in...5
×

Scala Sjug 09

1,779

Published on

Scala talk for Sydney JUG, September 2009.

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

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

No notes for slide

Transcript of "Scala Sjug 09"

  1. 1. Scala – why you should care SJUG @ Atlassian HQ, 2009 Michael Neale JBoss R&D Red Hat Middleware 1
  2. 2. Michael Neale R&D w. JBoss (specialise in drools) Open source history (user -> fulltime developer “acquired” by jboss 2005). Thanks Atlassian ! me on the web: www.michaelneale.net, twitter.com/michaelneale, michaelneale.blogspot.com Some slides borrowed from Jonas Boner ! 2
  3. 3. Outline • The elevator pitch • Why another language? • Scala in more detail • Actors/concurrency • State of the tools • How to integrate/migrate • Q&A 3
  4. 4. Quick intro • Scala is a OO/FP hybrid language • Statically strongly typed • Scala is a compiler + small (ish) rt.jar • Compiles statically to bytecode • Interops fawlessly with JVM/java code (in source**, or library form in both directions) • FP favour (but not “pure”) • Both more static and more OO then java 4
  5. 5. What's it like to drive 5
  6. 6. The surface diferences... public Integer methodName()... public void another(String s)... def methodName : Integer = {...} def another(s: String) = {...} String x = “abc”; final String y = “def”; var x = “abc” val x = “def” public class MyClass class Foo (punctuation generally optional: brackets, semi-colons etc..) 6
  7. 7. final Map<String, Integer> m = new HashMap<String, Integer>(); m.put(“hello”, 42); m.put(“goodbye”, 42); val m = Map(“hello” -> 42, “goodbye” -> 42) /* Actually a smaller grammar then java ! */ 7
  8. 8. Higher level 8
  9. 9. 9
  10. 10. Closures... fnally Pascal has them, Even C has them... (age: Int) => println(“I am “ + age) val fn = (age: Int) => .... 10
  11. 11. Why another language Java showing its age Was built in a hurry, unable to shoe-horn enough in... (eg. unable to agree on Closures) Well documented issues... (and some don't want it to change) But JVM is made of awesome... 11
  12. 12. 12
  13. 13. But why Scala... • Why not? • Valid javac successor (true to the intentions of Java, static typed, fast etc) • Designed by expert(s) – Based on hard won lessons • Not dynamic, nice for “systems” programming • Obey ! (and Gosling likes it) 13
  14. 14. Slightly deeper • Scala is very deep, but you don't have to know that much (unless you are a library author, probably). • Can write it as “nicer java” if you like, but lends itself to FP 14
  15. 15. 15
  16. 16. Just so you know I am not making this up... 16
  17. 17. Using java libs.. • Just works • Arrays in java are “decorated” to be like “Lazy sequences” • (previous slide was JExcel API) • Other common data types are “often decorated” to be scala-friendly • Outgoing library: use java collections, Arrays etc as you would like to see them 17
  18. 18. Lazyness... • Hard work pays of eventually • (but lazyness pays of now) • Lazy can be GOOD in a language • “lazy” keyword, lazy sequences.. – But can be some traps: put in a print statement and it will exec, remove and it won't... - heisenbugs 18
  19. 19. Dynamic language “magic” • Monkey patching → Implicits • Duck typing → Structural typing 19
  20. 20. Implicits... .. Is how you “extend” a class Anywhere “in scope” - called automagically With great power comes... Its compile time and safe 20
  21. 21. Structural typing 21
  22. 22. Traits... • Like interfaces, but can have implementations in it • “Mix ins” - compile time or construction time //Interface: trait Funny { def laugh } //With impl: trait Person { def tickle = println(“hahaha”) } class Michael extends Funny... val x = new Michael with Person //doesn't have to implement Person ! 22 e:
  23. 23. Pattern matching 23
  24. 24. Everything is.. • An expression that returns a value • “Unit” is like Void • Even if “statements”, pattern matches etc. 24
  25. 25. DSL friendly • Malleable syntax (internal DSLs) • Parser combinator library (write parsers in scala) 25
  26. 26. Concurrency 26
  27. 27. Option/Either • “Monad” patterns • Don't have to care, just return option if you are not sure if you will have a result • (or either if its, well 1 of 2 things...) • Very easy to use, correct code, very neat... 27
  28. 28. State of the tools • IntelliJ demo time... • Eclipse – well, maybe with 2.8 • Netbeans: Good ! • Emacs/textmate ?? • Maven works well (/me ducks) 28
  29. 29. Who is using it ? • Big Important companies all over... • Twitter ! • EPFL, Jetbrains etc committed to continuing development and stability and tools ! 29
  30. 30. Some extra magic • QuickCheck (ScalaCheck) – Demo – import org.scalacheck.Prop.forAll – scala> class FeeCalculator(val tax: Int) { – | def howMuch(tx: Int) = tx + tax + 42 – |} – val totals = forAll( (amounts: Int) => new FeeCalculator(2).howMuch(amounts) > amounts ) – totals.check 30
  31. 31. Mixed source... • Scala compiler can work with mixed java and scala source • (multiple passes) – similar to groovy • Means you can migrate over only what you need • Preferred: have modules in all scala or java. 31
  32. 32. Case classes • Case classes help you out (equals, hashCode, pattern matching) • No “new” needed • Eg: case class Car(type: String, cost: Int) val c = Car 32
  33. 33. Anti static • No statics in Scala • But you can swap “class” for “object” and its kind of sort of the same (but better) object MyObject { … } val x = MyObject MyObject.whatever 33
  34. 34. Resources... • scala-lang.org • A few good books (Programming In Scala) and growing • #scala on freenode 34
  35. 35. Conclusion... • Very powerful, mature, fun ! • Would you use it over groovy? • No “grails” or “rails” (Lift just Ain't It). • Thanks ! • Discussion and Q&A • twitter.com/michaelneale • www.osdc.com.au - Brisbane in Nov. 35
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×