Posted 2010-06-16 18:43:32 GMT
The Scala programming language has all the features of Java, and supports all sorts of fun things like closures, higher-kinded types and inline XML. If you're starting a new project for the JVM, shouldn't you just use Scala?
The Scala environment is very interesting and in 2.8 has the ability to pass around unboxed primitive types through to functions that are specified over multiple types — so that generic functions no longer have a massive performance penalty.
Scala has operator overloading, and even the ability to give the appearance of adding new methods to existing types via the implicit mechanism.
These things make the task of writing code much more convenient. There's less need to explicitly distinguish between arrays and other sequences and unboxed doubles and other numeric types. Papering over the division between arrays, primitive types and reference types in the JVM actually reduces to some extent the conceptual complexity of using it.
But these ideas are fundamentally opposed to the reason Java came into
being. Scala positions itself as
language designed to express common programming patterns in a concise,
elegant way. Java is culturally opposed to these ideas: it is
Java design team examined many aspects of the "modern" C and
C++ languages to determine features that could be eliminated in the
context of modern object-oriented programming while still
retaining some similarity to C++ syntax.
In particular, a founding principle was that everything should
be very explicit:
A major problem with C and C++ is the amount
of context you need to understand another programmer's code: you have
to read all related header files, all related #defines, and all
related typedefs before you can even begin to analyze a program. In
essence, programming with #defines and typedefs results in every
programmer inventing a new programming language that's
incomprehensible to anybody other than its creator, thus defeating the
goals of good programming practices.
This definition of a good programming practice is one that Scala vehemently opposes. The ability to write domain specific languages that integrate with the core is promoted as a positive.
In my opinion, the definition of a good programming practice should include whether or not it gets results. After the HotJava experiment failed perhaps it's time to admit that all three major webbrowsers (Mozilla Gecko, Webkit, and Internet Explorer) are all written in C++ for real reasons and not just force of habit.
Java was supposed to start small and grow as a reaction against the perceived causes for which languages like Lisp and Smalltalk were rejected. Scala is proud of the power of its higher-kinded types: Java is proud of removing multiple inheritance. They're not really competitors: the cultural gulf is huge.
Perhaps Scala will be able to drag the JVM into competition with numerous other platforms. It has a good set of web companies (for example, Foursquare) using it as a replacement for programmer-orientated scripting languages, and that's where Scala has a natural fit, albeit with strong-typing.
Java is deliberately not programmer-orientated. That's the point of using it — it was designed to restrict the kind of trouble programmers can get themselves into. If you're stuck with the JVM, I guess the question is: how much rope do you want to give your programmers? Scala is essentially the opposite answer to Java.
Post a comment