They may automate some of the typing of boilerplate, but that just means the language you are entering isn't the same language you are reading, which is another problem.
The boilerplate is still there, and its still in the way.
> Sure, you have a little more code to look at. But frankly, sometimes this can improve readability vis-a-vis excessively concise and overloaded syntax.
IME, its more often the case that the boilerplate that Java requires makes code hard to read than that the conciseness that Scala permits (but generally does not require) makes it hard to read. And, since the concise options in Scala are generally options, a programmer who is aware of a case where being maximally concise impedes clarity can opt for a more explicit expression, whereas the Java-required boilerplate isn't optional, so even if the programmer is aware of it getting in the way of readability, they can't eliminate it.
I don't think that's true. Your phone has an autocomplete function for text input. You're still typing and reading the same language.
> a programmer who is aware of a case where being maximally concise impedes clarity can opt for a more explicit expression
By the same token, readers are held hostage by the poor decisions of overly concise Scala programmers. This is not theory, it really happens a nontrivial amount of time. You can blame the programmer if you want, but it's a point for Java readability.
Now you're simply overstating the case. Why?
This is a perfect example of my claim. There is this emotional component to the "Java boilerplate" argument that belies rationality. There is some other unstated reason advocates want Scala and are fitting the argument to that conclusion. Because it's cool? Big fish small pond syndrome?
List<String> list = getListofStrings();
List<String> capitalized = new ArrayList<String>();
for(String st : list)
if(Character.isUpperCase(st.charAt(0)))
capitalized.add(st);
Or... val list = getListOfStrings
val capitalized = list.filter(_.head.isUpper)
Grokking two lines will take less time than grokking six lines.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.
when your mental/visual pattern machinery have been trained for 15+ years on the latter case? :)
It can transform for loops into linq statements (and vice versa) quite easily
And even the best IDEs can't help with much of what I've seen in large Java apps.
I've always wondered about this argument. Haven't modern Java IDEs more or less automated away the boilerplate?
Using a tool like IntelliJ IDEA or even Eclipse for that matter, I'm really hard pressed to find something that could be autocompleted or generated that hasn't been. They even have views that collapse or otherwise hide away unnecessary verbosity.
Sure, you have a little more code to look at. But frankly, sometimes this can improve readability vis-a-vis excessively concise and overloaded syntax. It can make it easier to grok someone else's code.
I'm not saying there's no difference, just that it's a little odd that this is the NUMBER ONE advantage always cited for Scala vs. Java. Am I crazy?