Description
For a variety of cases, we should decide between alignment or non-aligning indentation. When breaking a line, should the item on the next line align with the item, or just have an additional level of indentation compared to the previous line? For instance:
fn alignment(arg: T,
arg2: T2)
fn indentation(
arg: T,
arg2: T2)
let aligned = (value1
+ value2);
let indented = (
value1
+ value2);
let indented2 = (
value1
+ value2
);
let structval_aligned = S { field: value,
field2: value };
let structval_indented = S {
field: value,
field2: value,
};
function_call_aligned(param1,
param2);
function_call_indented(
param1,
param2);
This seems mostly orthogonal to indentation size, line length, and where exactly to break various types of lines.
I would propose avoiding alignment as a general principle. While alignment can sometimes improve readability, it produces significantly more noise in version control, since changes to one line can ripple outward into spacing changes on many lines. Alignment also tends to more quickly drift to the right edge of the screen, and produces worse results when wrapping lines close to a line-length limit.
In many cases, breaking the line and indenting before the first item provides the same benefit without the corresponding problem.