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

or use a language/environment that allows for trailing commas...


Seriously! Every language should support this. Not just for arrays but in argument lists too! Python does a good job here but I can't think of anything else which does.


Perl does


Depending on other syntax facets, that can create ambiguity.

Does that trailing comma represent nothing (the end of the list) or an undefined/null/empty/whatever item (an extra item adding to the length of the list?

Even if the meaning is completely unambiguous as far as the language is concerned, that doesn't necessarily make it intuitive to humans especially in a mixed language scenario.


perl allows both trailing commas and also optional list-quoting which breaks on whitespace (commas unneeded):

    my @stuff = (
      "foo",
      "bar",
      "baz",
    );
or:

    my @stuff = qw(
      foo
      bar
      baz
    );
or

  my @stuff = qw(foo bar baz);
TIMTOWDI indeed...


This really is the sensible solution.


Hint hint: PHP does this!




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

Search: