Re: First Steps to Scala
Posted: Dec 30, 2007 11:47 AM
I am a long time C / Java programmer. Never used any functional languages, (well, I did use LISP very briefly many many years ago) most of this is new to me. Perhaps this ignorance shows in my (admittedly somewhat cynical) comments below.
Overall, I love the fact that Scala runs in the JVM and I can import familiar Java classes. (And, I assume, 3rd party jars such as Apache) The parts work, I can use Eclipse, I'll almost certainly give Scala a try. But I have a lot of quibbles with the syntax. IMO, they got too creative / cutesie.
You define an object as Singleton by calling it, DOH, object. Why not use the term "singleton"!
If :: is pronounced "cons", why not type it as cons? Geez, its all of 2 extra characters. And it's clearer - I see "cons", I wikipedia LISP, and I get a lot of info on what it means, plus links to cdr, etc... And it's less likely to get confused with :::. A common programming bug in confusing = and ==, why design in :: and ::: which are visually even closer?
treasureMap += 1 -> "Go to island.";
for adding to a map is truly the most disgusting syntax ever. This is almost enough to make me writeoff the language. BTW, this syntax is longer than Java's
treasureMap.put(1,"Go to island.");
I'm extremely leery of syntactically important white space which seems common in Scala (if I'm understanding some of these alternative syntaxes right).
"Sometimes the Scala compiler will require you to specify the result type of a method"
I saw something like this in another article about variables. leave off declarations till it complains and you learn better. So you "save" typing and are ultra efficient by leaving off "int" or "void", but then you waste time when the compiler complains. Call me a sceptic.
BTW, they should use void for void, not "unit". What the heck is unit?
Finally, about all the functional parts. Will somebody please please post a useful example other than printing an array of strings? When the key benefit of FP that 1000s of posts of Artima are demanding be added to Java is the ability to go
args.foreach((arg: String) => println(arg))
for (String arg : args)
I am, well, completely underwhelmed.