Hacker News new | past | comments | ask | show | jobs | submit login

I wouldn't call them "hacks", but some style choices that I have adopted for my personal code that I haven't seen often in other people's code:

1. (In C-style languages), indent labels by half the tab-size, using spaces. I find that indenting labels (jump labels, case labels, public/private/protected) makes them easier to distinguish as labels as opposed to something that delimits blocks, while at the same time I don't indent code under a label more than code not under a label.

  class Whatever {
    protected: // having the access modifier indented makes the class easier to read
      int i;
  };

  struct SomethingElse {
      char c;  // same indentation as in the class above
  };
2. Put complex logical expressions on multiple lines with the conjoining logical op first on the line, with internal indenting. By using the start of the line and using two dimensions, I think that it is faster for a human to parse top-down than otherwise. Example:

  if (   long-expression-with-boolean-result
      && (   second-long-expression-with-boolean-result
          || third-long-expression))
  {
      ...
  }



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

Search: