[Python-Dev] Py2.6 ideas
Larry Hastings
larry at hastings.org
Wed Feb 21 07:49:15 CET 2007
Josiah Carlson wrote:
> Larry Hastings <larry at hastings.org> wrote:
>
>> For new code, I can't think of a single place I'd want to use a
>> "NamedTuple" where a "record" wouldn't be arguably more suitable. The
>> "NamedTuple" makes sense only for "fixing" old APIs like os.stat.
>>
> I disagree.
>
> def add(v1, v2)
> return Vector(i+j for i,j in izip(v1,v2))
>
> x,y,z = point
>
I realize I'm in the minority here, but I prefer to use tuples only as
lightweight frozen lists of homogeneous objects. I understand the
concept that a tuple is a frozen container of heterogeneous objects
referenced by position, it's considered a perfectly Pythonic idiom, it
has a long-standing history in mathematical notation... I *get* it, I
just don't *agree* with it.
Better to make explicit the association of data with its name. x.dingus
is simply better than remembering "the ith element of x is the
'dingus'". The examples you cite don't sway me; I'd be perfectly happy
to use a positionless "record" that lacked the syntactic shortcuts you
suggest. I stand by my assertion above.
At least now you know "where I'm coming from",
/larry/
More information about the Python-Dev
mailing list