> All fine, I can live with it, but I just sometimes want to have a way to
> apply my formatting, because sometimes it feels to me like “programming art”,
> especially when I try to align stuff to fit each other. My example would be
> like ten lines with mostly the same stuff, but aligned by whitespace so you
> can interpret it visually like a “table” (like a table of constants).
I am very fond of formatting code manually, Uwe. But the reality of it
is that over time those manual alignments always go out of sync.
Sometimes you can "force" that google formatter to break a line here
and there by adding single-line comments, but I really would not
do it. In most cases the intention can be propagated in a different
way. For example, I've seen one-dimensional tables that were actually
tuples in tests. So something like:
String args [] = { "k1", "v1", "k2", "v2", ... };
When the list of arguments is long, it'll be formatted as vertically
aligned single-argument line. If you wish to convey the grouping, do
it like this:
String[][] args = { {"k1", "v1"}, {"k2", "v2"}, ... }
and the formatted code will visually organize these blocks. A similar
thing can be done to string concatenations -
return "arg1=" + arg1 + ", arg2=" + arg2 + ", arg3=" + arg3;
if you have logical groups of arguments, use parentheses to hint at them:
return ("arg1=" + arg1) + (", arg2=" + arg2) + (", arg3=" + arg3);
and it comes out formatted really nicely, with intentions clear and no
manual hacks needed.
Most other code can be adjusted in this way. I'm sure not *everything*
can be expressed and sometimes the formatter will make mistakes (it's
just a machine after all) but it's a tradeoff I warned about when I
suggested this change - sorry!
Dawid
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]