Java 8: Don’t mistake concision for readability

O’Reilly has a quick little eBook called Introducing Java 8 that, in exchange for your name and email, you can download now on Java 8 right now. If you haven’t spent much time looking at Java 8’s new features, it’s surely worth a download because it’s a quick and easy read.

If you do however, I hope you’ll come back and consider my comments.

My immediate and most prominent reaction to the book is that it appears to pile on to the idea that more code always makes code less readable. Here’s the compare/contrast he offers. This is old school:

According to the author, the following Java 8 syntax is both more concise and more readable:

I obviously can’t disagree that it’s more concise because there were five lines in the first example; one the second. Therefore, concision.

Squishier is the author’s conclusion that it’s therefore more readable. My first reaction was quite contrary. In the first example, I knew exactly what was going on (maybe because I’m old school and understand the APIs well). In the second, I didn’t think it was readable for lots of reasons:

  1. What is the comparingDouble function? It’s oddly named and I don’t know what kind of comparison it does. And where did it come from? Static import? If so, that adds an off balance sheet line of code.
  2. Why is there only one “Invoice” amount getting passed into the function? What invoices?? Comparing what to what?? What comes first and what comes last???
  3. What does “reverse” do?

I totally understand what the author was trying to do with the example because I’ve tried to put these kinds of juxtapositions together too. But I think he’s just going too far to drop a single line of code and conclude that it’s both more concise and more readable without explaining why.

And if you’ll allow me to go further, it’s an issue I have with the fashion industry mentality that too many developers have. Think critically. Just because it’s concise doesn’t make it readable. If you think it is, explain why. Am I just irrational? Look no further than some of the grep statements that “those grep people” put together to know that concision does not automatically result in readability.

Leave a Reply

Your email address will not be published. Required fields are marked *