News for hackers. Stuff that matters.
Re:Redesigning Python's named tuples by adambyrtek on Friday September 01, 2017 @05:44AM (#15147206)
It's called a tuple so why would accessing its elements by index be "bizarre" in any way?
Re:Redesigning Python's named tuples by coldtea on Friday September 01, 2017 @07:46AM (#15147583)
Because the whole point of namedtuples is to have them as a convenient quick notation for records.

But I was referring to the parent's general observation that about "catering to some obscure use case that nobody uses", which I agree with -- not about their specific example.

Re:Redesigning Python's named tuples by emmelaich on Friday September 01, 2017 @07:29AM (#15147519)
Because order should be unimportant for a tuple.
Re:Redesigning Python's named tuples by adambyrtek on Friday September 01, 2017 @08:28AM (#15147775)
Order is important for "pure" Python tuples, so I see no reason why it shouldn't be the case for namedtuple. Mathematical tuples are ordered as well:

"In mathematics a tuple is a finite ordered list (sequence) of elements. An n-tuple is a sequence (or ordered list) of n elements, where n is a non-negative integer. There is only one 0-tuple, an empty sequence. An n-tuple is defined inductively using the construction of an ordered pair." (Wikipedia)

Re:Redesigning Python's named tuples by joshuamorton on Friday September 01, 2017 @11:46AM (#15149477)
Followup:

Should order be important for a Tuple under a system that defines a Tuple as an immutable ordering?

That is, whatever your philosophical issues with namedtuple ordering, in python, a tuple is an immutable ordered list of things. In practice, tuples have taken the role of being type-heterogenous, known length, records.

One might then reasonably expect a namedtuple to be a type-heterogneous, known length, record, where attributes are named.

Re:Redesigning Python's named tuples by ageofwant on Friday September 01, 2017 @10:01AM (#15148353)
Tuples are ordered by definition. We use names for things to convey what they are, not what we want them to be. If you want a construct in which order does not matter, call it a set or a dict.
Re:Redesigning Python's named tuples by xapata on Friday September 01, 2017 @07:34AM (#15147531)
Are you joking or serious? I can't read your tone without emoji.
Re:Redesigning Python's named tuples by emmelaich on Friday September 01, 2017 @07:52AM (#15147612)
Serious; see coldtea's reply for a fuller explanation.

Or consider (firstname="John", lastname="Doe") vs (lastname="Doe", firstname="John").

I think you'd agree that they're the same.

Re:Redesigning Python's named tuples by rraval on Friday September 01, 2017 @08:26AM (#15147764)
They are the "same" by equality, but that's not the only relevant comparison. Ordering is important if you want lexicographic less than.

Without ordering, you wouldn't be able to sanely run `sorted` on a iterable of namedtuples.

Re:Redesigning Python's named tuples by tomrod on Friday September 01, 2017 @10:55AM (#15148808)
Dumb question from a non-developer: wouldn't using a dict object make more sense if someone wanted an unordered named tuple?
Re:Redesigning Python's named tuples by coldtea on Friday September 01, 2017 @11:43AM (#15149428)
It's not about the storage (besides Python also has order dicts).

Namedtuples are for the convenience of creating a record type (though indeed as others say, treating it as tuple where things expect a tuple is also a benefit).

Re:Redesigning Python's named tuples by xapata on Friday September 01, 2017 @05:13PM (#15152427)
A dict is appropriate for labeled data. Currently unordered, but likely to keep insertion order in v3.7 and later.

Don't call it an unordered namedtuple. That's confusing, because tuples are ordered.

Re:Redesigning Python's named tuples by emmelaich on Tuesday September 05, 2017 @12:11AM (#15172465)
You could order with a custom comparison; specify the columns* to be ordered as in a SQL 'ORDER BY'.
Re:Redesigning Python's named tuples by cocoablazing on Friday September 01, 2017 @08:29AM (#15147780)
I would expect that construction to result in identical behavior for dict() and certainly not anything calling itself a tuple. NamedTuples behaving in the manner you expect violates LSP with respect to tuple().
Re:Redesigning Python's named tuples by xapata on Friday September 01, 2017 @05:15PM (#15152436)
I disagree. As of v3.6, the order of keyword arguments is preserved.
Re:Redesigning Python's named tuples by lou1306 on Friday September 01, 2017 @07:40AM (#15147559)
Typically tuples are ordered lists of values. See Codd's relational model, Linda, Erlang, etc.
Re:Redesigning Python's named tuples by coldtea on Friday September 01, 2017 @07:43AM (#15147569)
In the relational model the order shouldn't matter:

  A relation is defined as a set of n-tuples. In both mathematics and the 
  relational database model, a set is an unordered collection of unique, non-
  duplicated items, although some DBMSs impose an order to their data. In 
  mathematics, a tuple has an order, and allows for duplication. E. F. Codd 
  originally defined tuples using this mathematical definition. 

  Later, it was one of E. F. Codd's great insights that using attribute names 
  instead of an  ordering would be so much more convenient (in general) in a 
  computer language based on relations. This insight is still being used today. 
  Though the concept has changed, the name "tuple" has not.
Re:Redesigning Python's named tuples by lou1306 on Friday September 01, 2017 @08:03AM (#15147644)
I stand corrected; I was probably fooled by the naming. Still, in most contexts tuples are ordered while sets/bags are not.
Re:Redesigning Python's named tuples by emmelaich on Saturday September 02, 2017 @01:04AM (#15154376)
FWIW I was referring to the abstract pure tuple, not the tuple as implemented in Python and some other languages where order is very useful.

"inessential" might be a better than "unimportant"