Type alignment in struct definitions


#1

What do people think about aligning types in structs? An example,

struct Foo {
    ab:   u32,
    abcd: u32,
    a:    u32
}

As opposed to

struct Foo {
    ab: u32,
    abcd: u32,
    a: u32
}

Should this be encouraged, discouraged, or left up to the developer?


#2

Our current style guide says to never do this. Personally, I like aligning the :.


#3

I did this for many years, but stopped because you often end up with a longer, newer field later (or remove the longest), and then commits span more lines than they have to.


#4

I am against this, as adding a field might potentially make you have to change everything.


#5

Superficially, it looks good, but I think it ultimately results in too much whitespace churn as fields are added/removed and everything has to be realigned.

It also doesn’t make sense for public fields, because public fields should have a doc comment, and that separator removes the need for alignment. I don’t think it makes sense to have a style rule that would only ever apply to private fields.