On Tue, Aug 29, 2017 at 7:07 PM, L. David Baron <dba...@dbaron.org> wrote:

> On Tuesday 2017-08-29 18:32 -0700, Eric Rahm wrote:
> > Do we explicitly state a preferred alignment of arguments in multi-line
> > function declarations (primarily in the context of C++) [1]? This
> question
> > has come up in regards to using clang-format for cleaning up code [2] and
> > it would be helpful to be able to reference a concrete example in the
> style
> > guide.
> >
> > Given this example:
> >
> > int
> > Foo(const nsACstring& aStr,
> >     mozilla::UniquePtr<const char*>&& aBuffer,
> >     nsISupports* aOptionalThing = nullptr);
> >
> > Should the reformatted style:
> >
> > a) *stay the same*
> > b) align the argument names like so:
> >
> > int
> > Foo(const nsACstring&                 aStr,
> >     mozilla::UniquePtr<const char*>&& aBuffer,
> >     nsISupports*                      aOptionalThing = nullptr);
> >
> > c) some other option
>
> I don't know if we've had any official statements, but I tend to
> reformat code *away* from option (b) towards your original example
> if I'm modifying it and need to add a parameter than would throw
> things out of alignment.
>
> I think I do this because (b) has the disadvantage that more code
> changes require touching additional lines, which is both changes
> blame and is extra work (although it's not extra work if we're using
> clang-format tree-wide).  Option (b) is also more likely to lead to
> overly long lines that require wrapping.


I agree with dbaron.

Vertical alignment just creates more work and code churn. Keep it simple
and don't require extra code to be changed just because you rename or
add/remove arguments. We should be encouraging code to be refactored when
justified. Extra, avoidable code churn via vertical alignment therefore
discourages cleanups and is counter-productive to long-term maintainability.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to