Leaving comments aside, I'm going to address just the misunderstandings in your quoted code:
On 3 August 2010 09:41, Wildam Martin <mwil...@gmail.com> wrote: > > 1. Strangely too many different possibly approaches to implement the same > thing. > I like to have options, but where it makes sense. I mean, I already > have two options to start a console program: > > object Main { > def main(args: Array[String]) { > [...] > > and > > object somestuff extends Application { > [...] > > (I have seen 5 ways to write the same simple stuff in other cases > which I unfortunately can't recall now - just ridiculous it was!). It > is hard enough to read others code, but such things makes it worse. > > Guilty as charged... The Application trait is a sad moment in Scala's history, we try to forget about it... It's been show to be a Very Bad(tm) thing, and has long been deprecated. Your first example is the one true way :) > 2. Readability > No, this is not (just to give one example): > val elems = args map Integer.parseInt > println("The sum of my arguments is: " + elems.foldRight(0) (_ + _)) > > Ouch! That truly is an ugly way to handle such a simple concept. Try this version instead: println("The sum of my arguments is: " + args.map(Integer.parseInt).sum) > > 3. Functional approach > I could never get warm with functional programming, Scala does not > make a difference here. > > YMMV. > > See my response to point 2. That solution wouldn't be possible without the ability to pass Integer.parseInt as a closure/function to the map method, this is the essence of functional programming There are some other (admittedly complex) backstage tricks to make the magic happen; specifically, implicits and higher-kinded types but... these are all handled in the collections library, as an end-user you can simply call sum on *any* collection of numbers It will "just work", and yield a number of the correct type (int/float/double/etc.) It's still statically-typed, but feels to the end-user very like a dynamic language -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to javapo...@googlegroups.com. To unsubscribe from this group, send email to javaposse+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.