Parenthesis (and dots) (in Scala (as compared to Ruby))
Posted on November 4, 2012· 1 minute read
I must say that I quite like what I encounter of the Scala language in Martin Odersky's online "Functional Programming in Scala" course at EPFL (as well as the course itself!). It is almost as expressive as my favourite language these days, Ruby. (Of course it will never really be able to match it on expressiveness, I'd say (the latter being duck typed, and the former being strictly typed (even with a most excellent type inference)).)
One detail that I like about both languages is that parenthesis are (most of the times) optional. (By "(most of the time)" I mean that you (obviously) can't really skip them if it leads to problems with operator precedence.) This (can) really lead(s) to more readable code. Scala, however, (seemingly) has some inconsistencies when it comes to when they are needed. Most notably the println (and similar?) function(s). ((Quite possibly inspired by scripting languages) you have a quick way to display text at the user with println instead of Java's ghastly System.out.println(). Thats nice.) But arguments for this function, requires for some reason to be encapsulated in parenthesis. (In Ruby it would simply be a matter of puts'ing - with or without parenthesis.) The same seems to apply for higher order functions as arguments to functions...
Am I missing something?
(To Scala's defence it also allows skipping .s in function calls, which can also potentially lead to more readable code.)