Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Yes, 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.


The 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()


Yep.


Put two spaces before your literal code blocks, your newlines are getting eaten up by the formatter.


Did so thanks!




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: