HACKER Q&A
📣 fardinahsan146

What are your programming ergonomic hacks?


I usually place syntax commas in the begging of a line.

For example:

```sql select column1 ,column2 ,column2 from table ```

Or

function( arg1 ,arg2 ,arg3 )

---

Some people have a strong reaction to this. But I think its strictly superior in that I can comment out a line without having to add or remove any commas on the line above.

This is quite obvious, but I do feel like I never put much thought into programming ergonomics. What are some similar "hacks" that you know or use?


  👤 Findecanor Accepted Answer ✓
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))
  {
      ...
  }