4 ms·
...or one could just use Python without classes, just functions. TBH I never quite understood why Python has the class keyword, it's a much better language with
by flohofwoe 5y ago
...or one could just use Python without classes, just functions. TBH I never quite understood why Python has the class keyword, it's a much better language without.
- ledauphin 5y agoattrs really isnt about OO-style classes - it's specifically meant to provide struct-like declarative data containers, and these can help bridge the gap between the toolset that Python provides and functional (data-first) programming styles.
- rthomas6 5y agoI thought like you for several years. Then one day, I needed a custom type. You can use dicts (or lists, or namedtuples, I guess?), but it just ends up being cleaner and more idiomatic to define a class for the type, because you can define common methods for them. The article mentions quaternions. If you make a quaternion type (class), you can define addition, multiplication, comparison, etc. for it (methods). If you represent a quaternion any other way, you can't say a * b. Or maybe you can, but I don't know how.
- lvass 5y agoYou can represent it as whatever and monkey patch it's __mul__. It's a bit complicated with standard library structures that may be implemented in C, though.
- Starlevel001 5y agoThis is an obvious troll post but python is a pure OO language, everything is a an object with an associated class. Functions are just instances of FunctionType.