[Python-ideas] Fwd: Anonymous namedtuples

Guido van Rossum guido at python.org
Tue Apr 19 11:13:53 EDT 2016


A general warning about this (x=12, y=16) idea: It's not so different from
using dicts as cheap structs, constructing objects on the fly using either
{'x': 12, 'y': 16} or dict(x=12, y=16). The problem with all these this is
that if you use this idiom a lot, you're invariably going to run into cases
where a field is missing, and you're spending a lot of time tracking down
where the object was created incorrectly. Using a namedtuple (or any other
construct that asks you to pre-declare the type used) the incorrect
construction will cause a failure right at the point where it's being
incorrectly constructed, making it much simpler to diagnose.

In fully typed languages like Haskell or Java this wouldn't be a problem,
but in languages like Python or Perl it is a real concern.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160419/0a314b42/attachment.html>


More information about the Python-ideas mailing list