4 ms·
I'm at 30 years of programming in C, and don't understand the comment. I've never had a problem with either curly brace placement. If a line is deleted, and tha
by kazinator 7y ago
I'm at 30 years of programming in C, and don't understand the comment. I've never had a problem with either curly brace placement. If a line is deleted, and that line is a curly brace, there will be a syntax error. "git diff" (or whatever you're using) will show you what lines you have deleted.
Both ways have some merit. Cuddled curly is good for ismple one-liners. Curly on next line is when the statement header is stuffed with multi-line expressions.
After all the years, I have settled on:
while (simple) {
}
while ((big || complex)
(condition && multiple && lines))
{
}
for (i = 0; i < MAX; i++) {
}
for (big_initialization;
big && step;
complex, increment++)
{
}
- jacquesm 7y agoThose all work because in all cases single deleted lines will generate an error message.
- kazinator 7y agoWhy are you still going on about this bizarre single line deletion phenomenon? The only way a single line deletion that contains curly braces will still compile is if it contains balanced curly braces: if (cond) { foo } stmt; All styles which avoid this do not have an issue with the deletion of random single line that contains a curly brace. Regardless of bracing style, we can easily find lines in a program which can be deleted without causing a compile error, just not ones which open a syntax without closing it and vice versa. Try not to randomly delete lines from your program, and inspect your "git diff" or what have you should such a thing happen.