All of them are better then never wrapping the line at all.
Agreed
I'd love to hear about your favorites sometime because I don't really have a favorite.
So, here's my personal list:
- Don't end lines with
(
Instead of
Thing ReaaaaaaaalllllllllllyLongFoo = SomeLongThing.someMethod(
arg1, arg2, arg3);
Thing ReaaaaaaaalllllllllllyLongFoo =
SomeLongThing.someMethod(arg1, arg2, arg3);
- Don't let args be lonely by themselves if possible
Exception e = ElasticsearchException("this is a really long message and other things",
"another string", err); // <-- 'err' has a friend
Exception e = ElasticsearchException("this is a really long message and other things",
err); // <-- it's so lonely!
This actually comes from prose, where justification and indenting usually should
never put a single word on a line by itself (it should pull a word from the
previous line down so it's not lonely). Tools like par
do this too if I recall
correctly (I could be wrong, I can consult my style manuals).
- If splitting a really long string, put the
+
at the end instead of the beginning of the next line
So instead of:
String foo = "this is a "
+ "really long string";
String foo = "this is a " +
"really long string";
Because it makes it more apparent that the string is continuing below when you read the first line.
- Don't put
);
on its own line
It's totally okay to have });
on its own line for things like classes and
Runnables and such, but not things like:
Object foo = MyAwesomeObject("foo", 12.03, 4,
"more arguments"
);