News for hackers. Stuff that matters.
Re:Scala: sharp and gets things cut by abalone on Monday October 07, 2013 @03:50PM (#6510729)
> Scala is for those that want to get shit done without dealing with Java's endless boilerplate

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?

Re:Scala: sharp and gets things cut by dragonwriter on Monday October 07, 2013 @04:36PM (#6511072)
> I've always wondered about this argument. Haven't modern Java IDEs more or less automated away the boilerplate?

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.

Re:Scala: sharp and gets things cut by abalone on Monday October 07, 2013 @06:41PM (#6511803)
> that just means the language you are entering isn't the same language you are reading

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.

Re:Scala: sharp and gets things cut by dragonwriter on Monday October 07, 2013 @09:09PM (#6512373)
A bad programmer can write code with poor readability in any language. That's no excuse for a language that makes clear, concise code impossible.
Re:Scala: sharp and gets things cut by abalone on Monday October 07, 2013 @11:28PM (#6512868)
> a language that makes clear, concise code impossible

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?

Re:Scala: sharp and gets things cut by saryant on Monday October 07, 2013 @04:31PM (#6511043)
I think the conciseness can improve readability. Consider these examples:

  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.
Re:Scala: sharp and gets things cut by abalone on Monday October 07, 2013 @06:34PM (#6511774)
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.

Re:Scala: sharp and gets things cut by gclaramunt on Monday October 07, 2013 @11:47PM (#6512932)
Is 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.
Re:Scala: sharp and gets things cut by VladRussian2 on Monday October 07, 2013 @04:45PM (#6511135)
>Grokking two lines will take less time than grokking six lines.

when your mental/visual pattern machinery have been trained for 15+ years on the latter case? :)

Re:Scala: sharp and gets things cut by dragonwriter on Monday October 07, 2013 @04:55PM (#6511198)
Sure, if you are excessively habituated to reading Language X and have some kind of barrier to learning new things, Language X will be better for you for most uses. That's not really a feature of Language X, though.
Re:Scala: sharp and gets things cut by saryant on Monday October 07, 2013 @04:56PM (#6511203)
IMO, the latter example is more readably because you're describing the result of the function rather than the outlining the operation itself.
Re:Scala: sharp and gets things cut by Dewie on Monday October 07, 2013 @06:10PM (#6511649)
An IDE that could take the first example, then hide it, and then infer what that would look like with more higher order functions (the latter example), and then display that, that would be a truly magical IDE...
Re:Scala: sharp and gets things cut by BSousa on Tuesday October 08, 2013 @07:07AM (#6514053)
Welcome to Visual Studio with Resharper :)

It can transform for loops into linq statements (and vice versa) quite easily

Re:Scala: sharp and gets things cut by Dewie on Wednesday October 09, 2013 @02:56PM (#6523099)
Damn, that's what I get for trying to be funny :)
Re:Scala: sharp and gets things cut by threeseed on Monday October 07, 2013 @04:25PM (#6510999)
Boilerplate code isn't just a problem for the person creating it. It's for the 20 people afterward who are going to be browsing, maintaining and adding new features on top of it. It is also lines of code that serve no purpose.

And even the best IDEs can't help with much of what I've seen in large Java apps.

Re:Scala: sharp and gets things cut by eranation on Monday October 07, 2013 @04:29PM (#6511024)
You are not, but subjectively I move more of my code to Scala, maybe java8 will change it, probably not. It's very much a personal choice. The easiest way is simply to write some code in Scala and get a feel for it. I prefer Scala because it's working for me, but everyone has different criteria and personal preferences. Go, clojure, Haskell might have more hype, but I tried them in the ultimate test of my productivity, and stayed with Scala. Because of my experience, not because someone convinced me in a comment or post. It's too subjective.
Re:Scala: sharp and gets things cut by auggierose on Monday October 07, 2013 @04:07PM (#6510848)
You are either crazy or maybe just not a very good programmer, if you think that tons of boilerplate is no problem because sometimes your IDE can generate / hide some of it for / from you.
Re:Scala: sharp and gets things cut by Dewie on Monday October 07, 2013 @06:13PM (#6511662)
Unless an IDE can hide 5 consecutive for-loops and then translate it into the equivalent composition of higher-order functions (with intermediate assignments for readability... but how will a code generator know what's readable) and then display that instead, I don't think that more functionally leaning programmers will think that IDE-generated code and code-hiding accomplishes the same thing, vis-a-vis what they might mean by "boilerplate".