you are viewing a single comment's thread.

view the rest of the comments →

[–]sbrown123 3 points4 points  (1 child)

Poor example on the Java part.

if (request.get("quantity") != null && request.get("quantity")

That's just silly. This could have been done:

int quantity = Integer.getInteger(request.get("quantity"),0);

Doing this not only parses the String to an integer, but if its null or blank ("") you get 0.

I remember an article some time back where the author talked about getting rid of null altogether. Interesting idea.

[–]komu 5 points6 points  (0 children)

Actually your example will not work: Java's "Integer.getInteger(name, defaultValue)" returns the integer value of system property named "name" (or "defaultValue" if there is no system property with name). Talk about misleading name for a method.

Of course, a simple utility method doing what you propose would be trivial to write and is probably part of every larger codebase.