Is OOP Pythonic?
https://news.ycombinator.com/item?id=29914474I have had this dilemma ever since I started programming in Python 3 years ago.
I am a strong believer in procedural programming, with some functional goodness thrown in. My argument is that procedures and functions complement each other well. Procedures change state, while functions produce new state. Dennis Ritchie figured this out almost 50 years ago and granted us C. People loved and still love C for it's simplicity and clear separation of data and procedures. You were granted a way to introduce your own structured data types, and that simple but powerful feature was enough for all kinds of complex data representations.
So what all this has to do with Python? Well, Python has a builtin way of implementing structures, but because of it's dynamic nature, that representation in the end boils down to simple key-value pairs -> dictionaries. So, why Python programmers prefer making classes when the language has dictionaries? Not only is using builtin types faster, it should also be more Pythonic, since you are exploiting one of the core features of Python: it's dynamic nature. Just look at LOAD_ATTR opcode, it's insane how slow that thing is.
If it quacks like a duck...or better yet, if it has a key, it is easy to check. So why not use it more?