Skip to content

Comment on Python classes aren’t always the best solution

Comments

Since this seems to be a guide for programmers new to Python, I wish it made it clear that dataclasses are classes; @dataclass just provides a concise way of defining classes with default functionality for instance construction, equality, hash, and string representation.

Otherwise, this is a decent set of reminders for programmers coming from more class-oriented languages.

Good point. I wasn't sure from the given examples that overuse of classes in this way was all that harmful, e.g. the performance penalty hopefully shouldn't be all that significant. But then I remembered all the Python code I've seen that was obviously written by capable and experienced C++ programmers.

True. Same could be said of namedtuples.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.