Type alignment in struct definitions

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?

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

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.

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

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.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.