
On 12/12/2011 8:07 AM, Antoine Pitrou wrote:
On Mon, 12 Dec 2011 08:00:28 -0500 Ned Batchelderned@nedbatchelder.com wrote:
On 12/10/2011 9:42 AM, Oleg Broytman wrote:
On Sat, Dec 10, 2011 at 02:16:21PM +0000, Richard Prosser wrote:
Although I love Python there are some aspects of the language design which are disappointing and which can even lead to problems in some cases.
What really is disappointing is the number of people who criticize
Python without knowing it.
Another awkward 'feature' is the requirement for a trailing comma in singleton tuples, due I believe to the use of expression parentheses rather than (say) the use of special brackets like chevrons.
You do not understand the syntax. Parens do not construct tuples -
commas do. So for every tuple - even of length 1 - you must have a comma. The only exception is an empty tuple (of length 0).
I don't think we have to go as far as blaming the user. Tuple syntax is a little tricky, people often trip up on (x,) as a single-item tuple. You and I understand why it is, and there isn't a better alternative, but that one-item syntax sticks out when compared to the others: (), (x, y), (x, y, z), etc. This is a true "gotcha" as Richard originally expressed it.
I think it would be more of a gotcha if parentheses were enough to create a tuple, though. Parentheses are useful to group operations, either for stylistic / syntactic support (think multi-line statements), or to work around operator precedence. Creating a tuple by mistake because you put some parentheses where not necessary would be really annoying.
Believe me, I understand the issues. It is true, though that the single-element tuple syntax is often a surprise to people, and often well into their Python learning experience. We often repeat, "it isn't parens that make a tuple, but a comma." Then why when displaying a tuple does Python insist on using parens around it?
1, 2, 3
(1, 2, 3)
I'm not saying it shouldn't, it's a rhetorical question. The repr of a tuple always includes parens, even though "parens don't make a tuple." It's the best of all the options, but let's face it: it's confusing.
--Ned.
Regards
Antoine.
Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas