3 ms·
How about forbidding newlines in a single-statement if and requiring a newline after the first statement after the if? So this is allowed: if (foo) bar();
by TheLoneWolfling 13y ago
How about forbidding newlines in a single-statement if and requiring a newline after the first statement after the if?
So this is allowed:
if (foo) bar();
baz()
But this isn't:
if (foo) bar(); baz()
And this isn't:
if (foo)
bar();
baz()
Edit: formatting
- justinhj 13y agoYes, I was thinking along similar lines. If your coding standard strictly prevents known dangerous habits (and it should be for security related code). Insisting on putting all if body statements in braces would have prevented the Apple bug. A pre-processor checking for violations should be possible too. The heart bleed one seems much less related to language and more about design. The flaw was not spotting that a user supplied value was passed in to a dangerous function. Explicitly denoting what is trusted and what is not could possibly be a feature of a language out there, I don't know, but it's certainly something that could be architected in an existing language.
- Jtsummers 13y agoPut two spaces before your literal code blocks, your newlines are getting eaten up by the formatter.
- TheLoneWolfling 13y agoDid so thanks!
- jloughry 13y agoThe formatter ate your indentation. Is this what you meant? So this is allowed: if (foo) bar(); baz() But this isn't: if (foo) bar(); baz() And this isn't: if (foo) bar(); baz()
- TheLoneWolfling 13y agoYep.