3 ms·
If you write in this style then there's the possibility that someone else (or yourself in future) will add a second line, like: if(x % 2) vec
by logicchains 2y ago
If you write in this style then there's the possibility that someone else (or yourself in future) will add a second line, like:
if(x % 2)
vec^.push_back(x);
do_something_else();
under the mistaken assumption that the second line will also only run in the x % 2 case. People make mistakes, this particular one can happen, does happen, and has happened many times, and the compiler absolutely will not inform or warn you, because it doesn't know you intended the second line to run in the same if statement as the first (because C++ isn't whitespace sensitive). Is ruling out an entire class of bug really not worth the effort of just typing two more characters?
- j16sdiz 2y agoIndentation can be fixed with a code formatter in pre commit hook.
- dragonwriter 2y agoOr even an on-save or (and more likely to prevent this kind of error in a large file) as-you-type feature in your IDE/editor.
- dllthomas 2y agoAvailable autoformatting is great, but IIRC the Apple issue happened in an automatic merge. Autoformatting would still help it be noticed, when someone wondered why the formatter changed some bit of the code they hadn't touched, but a formatting check in with the automated tests would catch it faster.
- throwaway376512 2y ago> and the compiler absolutely will not inform or warn you False. https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmisleading-indentation https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#inde... https://clang.llvm.org/docs/DiagnosticsReference.html#wmisleading-indentation https://clang.llvm.org/docs/DiagnosticsReference.html#wmisle...