2 ms·
Ok, first of all your Java example is five lines not six. Second, a lot of the concision comes from omitting type declarations. I will argue this decreases the
by abalone 13y ago
Ok, first of all your Java example is five lines not six.
Second, a lot of the concision comes from omitting type declarations. I will argue this decreases the readability of the Scala example.
What kind of data structure does getListOfStrings return? With Java you know with complete certainty that it returns a List of String (and only String). With Scala you have to infer it from the method name and hope it's honest. Likewise with the filter function. Whatever your opinion is of explicit type declarations, they are not mere "boilerplate".
There are certainly other savings in your Scala example apart from types, like the filter lambda function. I'm just a bit incredulous that Scala advocates genuinely think this saves them large quantities of time over the course of a project vs. an IDE-assisted Java version. I mean, how much longer would it take you to write or grok that Java for loop? Seconds? How much longer to do it 100X in a project? Minutes?
There has got to be a deeper underlying emotional reason why people advocate Scala -- which is not to invalidate that reason at all. It's important to feel love for your tools. But be honest about it. It's not about saving hundreds of hours of time writing boilerplate.
- gclaramunt 13y agoIs not about writing the boilerplate, is about having to think at that level. In Java, you think "I loop through the Strings and if it starts with uppercase, I'll add it to a new collection (which I need to remember to intialize)", in Scala is more "filter the strings that starts with uppercase". And even if the IDE can generate most of it, it still shows it to you to modify the template, and even if later hides it, it still in your code, in your diffs. Besides, higher order functions are not the only thing, traits are an awesome tool for structuring separation of concerns, and java doesn't come closer.