helsinki scala club 27 3 2013 summary
play

Helsinki Scala Club 27.3.2013 Summary :) Multi-paradigm, strongly - PowerPoint PPT Presentation

Helsinki Scala Club 27.3.2013 Summary :) Multi-paradigm, strongly typed JVM language Runs on JVM (good Java interoperability) Exotic build tools (sbt) Very lean syntax Sometimes too _ Open source, backed by Typesafe


  1. Helsinki Scala Club 27.3.2013

  2. Summary :) • Multi-paradigm, strongly typed JVM language • Runs on JVM (good Java interoperability) • Exotic build tools (sbt) • Very lean syntax • Sometimes too _ • Open source, backed by Typesafe • Awesome for scaling up & out (w/ Akka) • Complex to master - easy to dip

  3. W h a t S c a l a ? Multi-paradigm = many ways to do a thing Opposed to i.e. Python’s ”one obvious (and best) way” No one thinking is by itself considered ”better” than the others. Immutable data structures often preferred, since they scale better and fit functional thinking. But you can use Scala simply as a ”better Java” (please don’t). Strongly typed Object oriented Functional Scripting languages

  4. W h a t S c a l a ? Runs on JVM Multiple JVM implementations, including 100% open source OpenJVM. Existing, well performing (and documented) platform. No need to reinvent primitives s.a. OS access, networking, basic multithreading. Up to C++ level performance, if HotSpot™ kicks in. Some language features (s.a. short, float, null) are there only for Java compatibility. Also other implementations (.NET, LLVM) are possible. Strong push because of existing Java libraries.

  5. W h a t S c a l a ? Exotic build tools sbt = Scala Built Tool (NOT ‘simple build tool’!) ”Does it all” attitude: handles apt-get and make functionality. Build scripts either .sbt or .scala . + sniffs dependencies between source code automatically (like C#) + fairly easy to get started - complex to master - expects a certain directory structure (Scala itself doesn’t) - slooooooooow (well, compiling Scala is!) DEMO

  6. W h a t S c a l a ? Very lean syntax Remember the charts? 3x less code than Java/C++ case class Point2d( x: Double, y: Double ) That’s a class. def +( v: Vector2d )= new Point2d( x+v.dx, y+v.dy ) That’s a method. That’s a closure. override def equals(o: Any): Boolean = o match { case oo: Point2d => (oo-this).norm < EPSILON case _ => false } That’s a method with multiple entry points (kind of).

  7. W h a t S c a l a ? Very lean syntax (cont’d) List(41, "cat") collect { case i: Int => i + 1 } That’s a ”partial function” with only entry for ints. List(-12, 41) collect { case i if i<0: Int => i + 1 } That’s a partial function with only entry for negative ints. More on partial functions: http://blog.bruchez.name/2011/10/scala-partial-functions-without-phd.html BACK TO TRACK

  8. W h a t S c a l a ? Sometimes too _ One can do this: But this is better: List(1,2,3) map (_+2) List(1,2,3) map (x => x+2) Definitely not this: Perhaps better: List((1,2),(3,4)) map (_._1) List((1,2),(3,4)) map { case (a,_) => a } Note: this is a genuinly okay use for ’_’ There are N uses for the poor ’_’ in Scala: - don’t use it as a variable name postfix (makes a ”partially applied function” aka C++ function pointer) - generally makes syntax browsing and compiler error messages awkward, at places - for most use there is a better (slightly longer, but more readable) alternative More info: www.slideshare.net/normation/scala-dreaded In Scala 2.10 some of the language features have become optional: they must be switched on by each source needing them, or by a global flag.

  9. W h a t S c a l a ? Open Source, backed by ”The languages that are properly financed will stick around.” - Martin Odersky (I think...) Scala itself is Open Source (BSD-like license) JVM itself is available as an open source implementation (OpenJDK) They have more than just the language: - Akka, ”event driven middleware for Scala and Java” - Typesafe Console, ”an enterprise-grade dashboard for monitoring your application” They also have (paying) customers: full list of customers

  10. W h a t S c a l a ? Awesome for scaling Akka is like Erlang programming model on JVM (naming after a Swedish mountain maybe not a coincidence?). - Scales up = fills all your cores - Scales out = fills your cluster Scala had multiple Actor libraries (Scala 2.9, Lift, Akka). Since 2.10 Akka seems to be the norm (slightly more complex, but without limits). Calxeda coming out with 1000 servers in a rack. Akka gives you means to tap into them, seamlessly. Manages grouping agents to resettable groups, etc. Manages failure and recovery. The Akka book is as thick as the Scala book.

  11. W h a t S c a l a ? Easy to dip Scala for Java Refugees = one doesn’t have to eat the whole elephant up front! - Allows coding as if ”a better Java” - Dip by creating one simple, practical piece in Scala first (remember: full Java integration!) - Twitter etc. have good summaries of their transition (pros/cons) - ”Getting over Java” (or C++) may be the most challenging part = do eventually learn the map, match etc. i.e. think in Scala. - Getting *back* to Java is painful! :) Complex to master Scala essentially packs C++, Scheme and a scripting language in ONE. :) ”Many ways” is always more complex than ”one obvious way” Good language for consultants!? :D the end

  12. Next? • Hardware accelerated JVM-based GUI framework • Part of Java 7 SE • Very suited to alternative JVM languages • DEMO: own code • Scene tree benefits (like JavaScript, but type safe) • Ready to touch • Markets - automotive, embedded, Fat Client • Hardware and OS requirements Homework: test out JavaFX Ensemble

Recommend


More recommend