I would like to have this as a feature in the language without having to import another "magic" module, something similar to case classes in Scala.<p>Let me dream :)
On going discussion on reddit about this article/subject: <a href="https://www.reddit.com/r/Python/comments/3qw7m4/improving_your_code_readability_with_namedtuples/" rel="nofollow">https://www.reddit.com/r/Python/comments/3qw7m4/improving_yo...</a>
When you combine namedtuples with something like simplegeneric you can write some pretty awesome functional code in python. I think of them not as just tuples with names but something akin to an immutable struct.<p>I tend to reach for namedtuples first now over classes because of this (and the fact that I don't do as much OOP in general).
One possible issue with this approach is that you may need to add methods in the future to the tuple.<p>For example, the following pattern would improve code readability as well (by making values available as attributes) but also allows you to extend it in the future when you need to add additional methods to your object:<p><pre><code> class Person(object):
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
</code></pre>
Example: p = Person(name="John", age=30, weight=78) and p.age for access. When needed you can add methods to this class while still keeping the code readable.
I use namedtuples, and am happy to have them. What I dislike is the 'rename' option and automatic conversion from whitespace or comma delimited field names.
namedtuples are a great feature of the language but this example could be solved just as well with a dict. Like why is `person_data` not a dict?<p>The overall codebase used in this example is smelly.
You can name your tuples in Swift as well, I just wish more people did that. It's increasingly annoying to get a tuple and have no clue what indices are used for what.