These days everyone seems to be writing about some of the "new" languages on top of the JVM - or podcasting that's absolutely awesome what A does with groovy or B does with Scala. So I decided to take a look at these "new" languages, too.
In the last weeks I read a lot about Scala, worked through the examples and started to play a little by myself. Basically I like the language very much, mainly because it blends the best of Java with functional programming - and some memories from my college Scheme classes are coming back.
However there are a few things I don't like. Type inference, at least how it is implemented in Scala, is one of it. I can perfectly understand that
Map<String,List<Map<String,Long>>> map =
new HashMap<String,List<Map<String,Long>>>();
is awful. In Scala you use type inference and write
val map = new HashMap[String,List[[Map[String,Long]]]();
which is much shorter. However this has one drawback: map is inferenced as being of type HashMap and NOT Map. This violates one of the basic programming principles I learned and am defending passionately: Program against interfaces and NOT against concrete classes.
(BTW: Neil Gafter made a proposal how to combine type inference with programming against interfaces: http://gafter.blogspot.com/2007/07/constructor-type-inference.html)
On a side node, did you notice how a immutable value is declared in Scale? With val. Guess how a mutable variable is declared? Right, with var. How stupid is that? Just one character difference between two fundamentally different types of variables? The difference is quite important as the first type allows for the purely functional share nothing approach, which makes concurrent programming so much easier, while var stands for the "traditional" approach of shared variables which must potentially be protected against concurrent access from different threads.
27 April 2008
05 April 2008
My blog
Hi,
this is my first blog and my first post. So, 'Hello World'.
I'm going to post here whenever I think I'll have something interesting to write.
So prepare to very irregural updates and articles mainly about software development in general and Java in particular.
Christoph
this is my first blog and my first post. So, 'Hello World'.
I'm going to post here whenever I think I'll have something interesting to write.
So prepare to very irregural updates and articles mainly about software development in general and Java in particular.
Christoph
Subscribe to:
Posts (Atom)