r/Python • u/RickSore • Nov 14 '17
Senior Python Programmers, what tricks do you want to impart to us young guns?
Like basic looping, performance improvement, etc.
1.3k
Upvotes
r/Python • u/RickSore • Nov 14 '17
Like basic looping, performance improvement, etc.
3
u/RaionTategami Nov 14 '17
OOP in my opinion is just bad. But that's my opinion. Never writing classes is obviously going overboard so I'm not really saying you should never do it. A good rule of thumb is only writing a class if you have a new data type. If you want to bundle data then things like dicts and tuples (esp named tuples) are better. I see people using them when they are not needed and their code would be much cleaner without them.
Here's a recent example a saw from a neural network lib. They wanted to create layers which you could then call;
People seem to love this pattern but this is maddening to see because this is a closure.
Not only is that shorter its less prone to bugs.
So what I should really say is try not to write classes, there's probably a better way.