Re: Style Guide for Java 5 Generics and Annotations
Stanimir Stamenkov wrote:
The "Code Conventions for the Java Programming Language"
<http://java.sun.com/docs/codeconv/> doesn't state rules for formatting
newer Java 5 syntax: generics and annotations. In this regard I've
thought some may prefer a "compressed" style with these:
Map<String,String> stuff;
instead of:
Map<String, String> stuff;
Map <String, String> stuff;
@MyAnn(name="foo",data={43,234,65,76,125})
String stuff;
instead of:
@MyAnn(name = "foo", data = { 43, 234, 65, 76, 125 })
String stuff;
What's your preferred style (which may differ for the two cases)?
Clearly this is a matter of programmer preference.
I personally put spaces inside the parentheses and prior to the opening angle
bracket. I also put spaces inside the curly braces. I also put a space after
each comma. I also put opening curly braces for control structures on their
own line because putting them at the end of the control statement line is just
plain goofy.
What do you think, isn't the "compressed" style harder to read? With
everything jumbled together it makes it more difficult for the eye to pick out
syntactic breaks - white space makes it neurological instead of cognitive,
therefore much easier and faster.
If I were a code reviewer I'd ding code for lack of white space as in the
"compressed" example.
Your exact use of white space may vary, but use the principle to empower the
non-cognitive automatic neurological attributes of the eye-brain circuit, not
force people to reason through every character.
--
Lew