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

(i'm not certain what aspect you are trying to discuss but i'm assuming braces-- as that seems the primary point in the article)

My personal solution (again for JS) would be to use a new line with no braces to split up an if-statement, but to never nest a braced statement as part a pseudo-one-liner, nor to nest many levels of one-liners - as these situations could lead to confusion.

Eg for the above;

  while ((len = getline(line, MAXLINE)) > 0){
    if (len > max) {
        max = len;
        copy(longest, line);
    }
  }
  if (max > 0)
    printf("%s", longest);
This is a personal preference- i find it adequately splits up a one-line `if(max > 0) printf("%s", longest);` statement to be clearly identifiable as an if (while/for/etc) block, without the verboseness of the extra line/2 for braces, which i personally find makes code harder to read.


If I'm intentionally writing a one-line if I will write it on one line. I think using an indented second line without braces is less clear, and more prone to problems later when the code is modified.

So I'd write:

  if (max > 0) printf("%s", longest);

or

  if (max > 0) {
    printf("%s", longest);
  }
but never

  if (max > 0)
    printf("%s", longest);




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

Search: