2 ms·
It's subjective, but personally I've found multiple-declarations always harm readability. It's especially terrible in C and C++, where you need to be on your g
by MaxBarraclough 2y ago
It's subjective, but personally I've found multiple-declarations always harm readability.
It's especially terrible in C and C++, where you need to be on your guard for whether all the variables are being declared with the same type or whether some are pointers. Even in languages without this quirk though, I find it still slows my comprehension.
Unlike readability, conciseness of code isn't a virtue in and of itself. I see little upside to multiple-declarations, but clear downside.
Language trivia: the D language does not follow C's rule, instead it guarantees all variables in a multiple-declaration statement all have identical type:
int* x, y; // x and y are both pointers to ints
https://dlang.org/spec/declaration.html#declaring-multiple-symbols https://dlang.org/spec/declaration.html#declaring-multiple-s...
- kbolino 2y agoI think only C/C++ have this annoying quirk. C# is the same as D here and multiple variables declared in Go also all have the same type: var x, y *int // both pointers to int