31
Implementation Details / Code formatting of C2's c++
« on: November 05, 2018, 07:59:56 PM »
This might seem like a minor issue, but wading through thousands of lines of Clang (I've cut away in excess of 30,000 lines of code), there are two coding habits that makes the code IMMENSELY hard to read.
One is single line if's:
This obviously is even worse when adding else as well. The problem here is when you try get an overview of a function. Here K&R + single statement on two lines is making something really horrid:
Basically it's hard what block ends where.
I prefer (1) single statements ifs ALWAYS on a single line, Allman style. Any of those would solve the problem, BOTH is best:
ALLMAN
K&R Single line:
ALLMAN single line:
I understand most have a preference for K&R, so I'm not going to fight for Allman. But that two line single statement is a killer.
Switch-case where "case" does not have indention is difficult for similar reasons, although the two line if is by far the worst.
One is single line if's:
Code: [Select]
if (foo)
do_something();
This obviously is even worse when adding else as well. The problem here is when you try get an overview of a function. Here K&R + single statement on two lines is making something really horrid:
Code: [Select]
namspace foo {
/* many lines of code */
void a_method() {
/* MANY lines of code */
do_struff();
if (foo)
do_something();
} // <- What ends here??
/* more lines of code */
} // <- What ends here???
Basically it's hard what block ends where.
I prefer (1) single statements ifs ALWAYS on a single line, Allman style. Any of those would solve the problem, BOTH is best:
ALLMAN
Code: [Select]
namspace foo
{
/* many lines of code */
void a_method()
{
/* MANY lines of code */
do_struff();
if (foo)
do_something();
}
/* more lines of code */
}
K&R Single line:
Code: [Select]
namspace foo {
/* many lines of code */
void a_method() {
/* MANY lines of code */
do_struff();
if (foo) do_something();
}
/* more lines of code */
}
ALLMAN single line:
Code: [Select]
namspace foo
{
/* many lines of code */
void a_method()
{
/* MANY lines of code */
do_struff();
if (foo) do_something();
}
/* more lines of code */
}
I understand most have a preference for K&R, so I'm not going to fight for Allman. But that two line single statement is a killer.
Switch-case where "case" does not have indention is difficult for similar reasons, although the two line if is by far the worst.