small medium large xlarge

26 Sep 2011, 19:30
Ljos (1 post)

Java has a lot of bloat when writing code, but please don’t use contrived examples to show this. Your isBlank-method example can be written a lot simpler then what you portray here.

public static boolean isBlank(String str) {
    return s == null || str.matches("\\p{Space}*?");

It’s still a bit more then the Clojure equivalent, but not nearly as bad as what you have written. This code is also a lot more readable. If you prefer you can write "\\s*?" instead of "\\p{Space}*?".

22 Oct 2011, 20:37
Relevance, Inc (5 posts)

This is not our isBlank example. It is pulled directly from the Apache Commons library. We use this example because it represents code that most Java programmers use on a day to day basis. It also helps make the reader aware of the many things that they need to keep track of (like branches, mutable state, and exit points) when they are programming in Java. We mention right before the example where the code comes from.

11 Apr 2012, 15:20
Jean-François "Jeff" Héon (4 posts)

I suppose it’s the same argument for having the Person Java example full of getters and setters instead of being simply public fields. Getters and setters being the common way even though if a the Person class is considered only as a data structure, I’d be tempted to have it with public fields instead. Or use a Java Map, but then we’re back in verbose land 8)

13 Apr 2012, 16:18
Nick Bauman (2 posts)

I bought the first edition. Already defstruct was not considered best practice when I got that version. Second edition now is priced to me like a new book when I’m fairly sure it can’t be all new. People who bought the first edition should get some kind of price break, no?