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

> "Different syntaxes for lists and tuples." -- Again, what? They're different types!

Lists and tuples have different syntax in a weird and surprising way. List syntax is straightforward, just square brackets and commas. Tuple syntax pretends to be list syntax with parentheses but it's actually only about commas except when it isn't.

Typically you write `(a, b)`, but the parentheses are only for precedence, and can be left out if it's unambiguous: `a, b`. You can write a 1-list as `[a]`, but a 1-tuple is `(a,)` because `(a)` is just `a`. An empty tuple on the other hand is `()`, without any commas, and with parentheses doing something other than precedence. It's very ugly.

I can't think of a better way to fit it into the rest of the syntax but I still count it as a flaw.




It’s the one of those common situations where there’s no perfect solution, so one from a number of suboptimal ones needs to be chosen. This rubs random folks in random ways, and is endemic to language design. Just try to design one without no such compromise.

In this case the problem stems from the overloading of parentheses. There aren’t any more paired delimiters in ascii available unfortunately. Perhaps t[] could have been chosen, but as you see it isn’t exactly elegant either.


Ah, yeah I see; there's an ambiguity in parsing expressions and tuples which could lead to subtle typing bugs. There's another ambiguity that (a for a in b) is not a tuple, but a generator, while [a for a in b] is a list.




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

Search: