[llvm-dev] Change coding style for argument alignment?

Hubert Tong via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 17 20:31:00 PST 2020


On Tue, Dec 15, 2020 at 10:04 AM David Greene via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Nikita Popov via llvm-dev <llvm-dev at lists.llvm.org> writes:
>
> > 2. It causes significant right-ward drift. Especially for declarations,
> > it's somewhat common for code ending up like this...
> >
> >    Foo SomeClassName::someMethodName(Bar &Arg1,
> >                                       Bar &Arg2,
> >                                       Bar &Arg3,
> >                                       Bar &Arg4) {
> >
> > ... because there is just enough space to fit each argument individually,
> > but still a need to break each one out on a separate line. Closure
> > arguments are another common case of very awkward formatting.
>
> FWIW, I have actually drifted toward this style in my own non-LLVM code.
> That is, if there are more arguments than can fit on a single line, each
> gets its own line.  For example:
>
> void short_args(double an_argument_name, int another_parameter);
>
> void long_args(double first_argument,
>                int second_argument,
>                int *third_argument,
>                int fourth argument);
>
This also saves the annoying pain of everything shifting within a line just
because an argument got added (which messes up line-based diffs). That pain
is most noticeable when adding new members (or just updating initializers)
in member initializer lists for constructors.


>
> I find this easier to read than:
>
> void long_args(double first_argument, int second_argument,
>                int *third_argument, int fourth argument);
>
> It's easier for me because I need only scan vertically to find the
> arguments, not both vertically and horizontally.
>
> Long function names can be problematic and you're right about changing
> names requiring reformatting.  I've toyed with this style:
>
> void a_really_long_and_descriptive_function_name(
>        double first_argument,
>        int second_argument,
>        int *third_argument,
>        int fourth argument);
>
> I haven't yet convinced myself that this is a good idea.  It looks too
> jumbled to me and is more difficult to immediately find the start of the
> argument list.
>
>                  -David
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201217/524a7978/attachment.html>


More information about the llvm-dev mailing list