4 ms·
> someone can come along and create an instance of the class in a non-standard way shrug just document the interface and stick to it. If you want to keep thi
by wyldfire 9y ago
> someone can come along and create an instance of the class in a non-standard way
shrug just document the interface and stick to it.
If you want to keep things simple, create data structures using namedtuple. You get really sane objects that are definitely POLA [1] compliant.
> You look at code and you have no idea what is what.
You should consider type hints [2] and/or docstrings [2].
[1] https://en.wikipedia.org/wiki/Principle_of_least_astonishment https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...
[2] https://docs.python.org/3/library/typing.html https://docs.python.org/3/library/typing.html
[3] https://docs.python.org/devguide/documenting.html https://docs.python.org/devguide/documenting.html
- hasenj 9y agoOur project at work is using 3.4 and full of legacy code, and typical python code always has something astonishing. I always use type hints when I write new code. Because 3.4 has no type hints for class member declarations I end up writing constructors that take parameters then assign them to self. This way PyCharm will properly detect the type of class members.