[llvm-dev] Change coding style for argument alignment?
David Greene via llvm-dev
llvm-dev at lists.llvm.org
Tue Dec 15 07:03:50 PST 2020
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);
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
More information about the llvm-dev
mailing list