3 ms·
That seems like a somewhat different case, though. Your approach will help prevent new bugs like this from being introduced, but won't help you against existing
by mikeash 11y ago
That seems like a somewhat different case, though. Your approach will help prevent new bugs like this from being introduced, but won't help you against existing examples of it in areas you're not currently working on. And just because it's been around a long time doesn't mean it's "working." Goto fail showed that the bugs can be subtle and easily missed for a long time.
- gravypod 11y agoYes, but from what I understand this bug is more commonly introduced in code that is being updated. Notice that I said "avoided", not "fixed". That is because I am rather focused on making code that is maintainable. I posted this original comment to have a dialogue about something I include in my programming practices. I wanted to see how other people viewed this as a development technique.
- MichaelBurge 11y agoYou didn't say it explicitly, but your original comment came off more like "This option is unnecessary and should be removed from gcc, since we can simply enforce a style of using curly braces everywhere" C doesn't do this, but I like this feature from Perl for single-statement checks: return if is_red($traffic_light); return unless is_green($traffic_light); In C, I usually put the early returns on their own line without curly braces, but place them all together at the start of the function to make it easier to spot inconsistencies.
- kbenson 11y agoI love that feature of Perl, and to be explicitly clear to those that are unfamiliar with it, Perl does not allow unbraced single line if's in the normal sense (pre-conditional ifs), and does not allow braced post-conditional ifs. For example, these are valid: if ( $foo ) { bar(); baa(); } quux() if $foo; And these are not: if ( $foo ) bar(); { bar(); baz(); } if $foo;