Skip to content

Instantly share code, notes, and snippets.

@dakrone
Created April 28, 2016 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakrone/bbc1e1f94a64959e08b3f4403d168384 to your computer and use it in GitHub Desktop.
Save dakrone/bbc1e1f94a64959e08b3f4403d168384 to your computer and use it in GitHub Desktop.

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"
        );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment