Software Secret Weapons™  
Want your own domain specific languages in Java? Use Scala! posted by Pavel Simakov on 2008-03-20 01:07:36 under Lambda
view comments
 


I am very glad that I attended Bill Venners's presentation on Scala on this week's Silicon Valley JUG meeting. His presentation was very simple to understand, but gave an effective demonstration of Scala language capabilities. The JRuby talk was the original reason I came to the meeting, but Bill sold me Scala... 

Several of my attempts to scale PHP, JavaScript, Ruby and Python did not go anywhere. The lack of strong types was a huge obstacle that I could not mentally overcame for anything over 3000-5000 lines of code. I consequently ignored Scala when it started to popup everywhere in the blogs because I assumed that it would be more of the same thing as those other languages.

But Scala is different - Scala has static typing. If you are programming in Java now and if you are looking to achieve higher levels of abstraction for existing or new large Java products or if you want to build domain specific languages (DSL) embedded in Java you got to look at Scala.

Scala is Java. Scala code compiles to Java bytecode, it uses JVM as a runtime and has full interoperability with Java. You can Scala code from Java and back, quite transparently and with minimum or no performance implication. There is no nee to learn the limits of another runtime. Everything you know about Java, JVM, garbage collection, class loading, threading, sockets and so on still applies. All you hardware, deployment scripts and application server licenses will continue to work. Read my other post explaining how to add Scala support to Apache Tomcat.

Scala is Statically Typed. Scala uses all the same primitive and basic types as Java. The types must be declared at designed time and resolved at compile time. The type inference can still be used so you don't have to declare types in many cases, but the typing is static.

Scala is Functional. Scala is functional having both functions as first class objects and variety of ways to limit or fully avoid side effects. The ability to control side effects is very important for large projects. With functional features of Scala there are now many more opportunities to control side effects cheaply and naturally.

Scala Simplifies Embedded DSL creation. Scala supports various forms of compact syntax and includes support for writing new control structures. The syntax can be verbose or compact - you choose. And you get to keep static typing and compile time error checking.

Bill Venners has a book on Scala. The book is a very good overview of the language and has enough Scala examples to see the power of the language and its relevance to Java. What is missing are rich examples on interoperability on Java to Scala that go both ways: from Java call Scala and call Scala from Java. Even if both of these languages run in the same JVM with the same bytecodes, we need to figure out some cookie cutter and simple ways to glue existing Java libraries and frameworks to new Scala extensions as well as the other way around.

How beautiful that I don't have to relearn everything I already know and can simply start doing new things all in the conform of Eclipse and Java!

Comments (2)

  • Comment by Andres Almiray — March 20, 2008 @ 2:14 pm

    Bill’s presentation was indeed a good one, it showed the functional side of Scala and the importance of the immutable/mutable paradigm, I’ll surely would love to have him speak again on mor advanced Scala features. I also hope that a Groovy talk is scheduled soon, it has often arisen during the Q&A portion of the talks

  • Comment by Ganesh — April 19, 2008 @ 10:34 am

    Good overview. I have been a big fan of groovy for quite sometime now. I always had one reason or another to postpone learning scala, but not anymore. I guess, I should give it a chance.


Leave a comment


  Copyright © 2004-2007 by Pavel Simakov SourceForge.net Logo