David Blevins kirjoitti:
On Oct 30, 2008, at 2:24 PM, Alex Grönholm wrote:
Dain Sundstrom kirjoitti:
On Oct 30, 2008, at 1:58 PM, Alex Grönholm wrote:
if (debug) {
System.out.println("This is a one liner");
}
I do not understand why the braces are necessary when the code
block is only 1 line long. I used to do that years ago but over
time I came to a decision to drop that practice since it didn't
increase readability (to the contrary in fact) and it didn't
particularly prevent any coding errors.
Not for me. I find it easy to make programming mistakes and it is
hard for me to read.
I on the other hand have strong issues with the one-liner you
presented. Maybe we could agree to use braces for all control
statements then? It takes up more space but at least neither of us
would question its readability aspect.
One liners are fine for short statements, otherwise I tend to use two
lines with braces.
One example where I really like it:
protected Class resolveClass(ObjectStreamClass classDesc) throws
IOException, ClassNotFoundException {
try {
return Class.forName(classDesc.getName(), false,
getClassloader());
} catch (ClassNotFoundException e) {
String n = classDesc.getName();
if (n.equals("boolean")) return boolean.class;
if (n.equals("byte")) return byte.class;
if (n.equals("char")) return char.class;
if (n.equals("short")) return short.class;
if (n.equals("int")) return int.class;
if (n.equals("long")) return long.class;
if (n.equals("float")) return float.class;
if (n.equals("double")) return double.class;
throw e;
}
}
If we can't agree than I'm fine with no recommendation as I don't have
a hard time reading any of those three formats.
-David
I have updated openejb_eclipse_cleanup.xml and added
http://paradoxx.dyndns.org/~demigod/openejb.importorder (Eclipse wanted
to name it this way).