Presentation is loading. Please wait.

Presentation is loading. Please wait.

Artūras Šlajus VS through eyes of Ruby programmer.

Similar presentations


Presentation on theme: "Artūras Šlajus VS through eyes of Ruby programmer."— Presentation transcript:

1 Artūras Šlajus VS through eyes of Ruby programmer

2 My experience

3 How everything started

4 Static Speedy JVM Open classes Strong OOP Mixins Syntax Functional Duck typing Threading Structural typing

5

6

7

8

9 Compiler optimizations! Esp. when using immutable structures
Why? Compiler optimizations! Esp. when using immutable structures Map1, Map2, ... Map, Tail recursion

10 ScalaTest Has awesome libs to aid in testing (TDD, BDD, you name it).
But we really use RSpec ;) Which brings me to...

11 Ruby and Scala integration
JRuby allows for native integration, meaning no C code for you! However, JRuby is still slow (at least for us). We use JSON IPC bridge (it's ugly, but it works).

12 Other thingies

13 {alliance_id => [Player, Player]}
Functional thinking I need to: [Player, Player, nil, ...] => {alliance_id => [Player, Player]}

14 In Ruby I'd have done hash = {} players.each do |player|
unless player.nil? hash[player.alliance_id] ||= [] hash[player.alliance_id].push player end hash

15 players.flatten.groupBy { _.allianceId }
In Scala I do players.flatten.groupBy { _.allianceId }

16 Compiles to JVM bytecode. Can call Java code natively.
Java integration Compiles to JVM bytecode. Can call Java code natively. Can be called from Java. However it looks a bit ugly: scalaObject.$plus$equals(javaObj) scalaObject.push(javaObj)

17 scala> def getCowN ame(colo r: String) = {
Ditch those nulls! scala> def getCowN ame(colo r: String) = { | color match { | case "Black" | "White" => Some("C OW") | case _ => None | } } getCowN ame: (color: String)O ption[jav a.lang.St ring] scala> getCowN ame("Bla ck") res0: Option[ja va.lang.S tring] = Some(C OW) scala> getCowN ame("Yel low") res2: Option[ja va.lang.S tring] = None

18 Ditch those nulls! scala> getCowName("Black").get
res1: java.lang.String = COW scala> getCowName("White") match { | case Some(cow) => println("We've got a " + cow) | case None => println("No cows here") | } We've got a COW

19 Ugly things

20 Complex type annotations
def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That What? But you don't need that often.

21 Compiler speed It has a lot of things to do. A lot slower than javac.
Use Simple Build Tool or Fast Scala Compiler!

22 Conclusion If I knew Scala existed when I started Nebula 44 - I probably wouldn't have used Ruby. Well, except perhaps for scripting. Scala is a kick-ass language combining best from Ruby and Java worlds.


Download ppt "Artūras Šlajus VS through eyes of Ruby programmer."

Similar presentations


Ads by Google