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

One of the better ways I've seen of dealing with this, generally used in SQL which is one of the less lenient languages I've seen, is to prefix new lines of the list with commas. That is, when constructing a list using multiple lines (which is where the trailing comma is most problematic), the first line is not prefixed with a comma, and all subsequent lines are.

E.g.

    var foo = [
      "aa"
      , "bb"
      , "cc"
    ];
The usefulness of this may not be readily apparent in this simplistic example, but when the term is complex or spans multiple lines, it becomes useful both as an indicator of a new term starting, and in that identifying the end of a large term often isn't nearly as easy as identifying that start.

E.g.

    var foo = {
      attr1: "foo"
      , attr2: "bar"
      , method1: function() {
      }
      , method2: function() {
      }
    };
I'll admit I don't often use this technique. Most commonly it is with large custom SQL queries, which themselves are fairly uncommon for me. That said, SQL often lacks the mitigating techniques that make this less useful in common programming languages (such as computing complex terms ahead of time and assigning the result, gradual building of data structures, etc.).


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

Search: