Smalltalk habits in Python
One of the things I picked up in Smalltalk is that a method should be tiny. In Smalltalk, many people would frown on a method that is more than 10-12 lines. This obviously is much larger than most Python methods in many classes, and so I started thinking about it. The main reason not to have lots of little methods (LOLM) is the dispatch overhead, but is that necessarily the right problem to be worrying about right now?
My decision was that I’m going to start using the lots of little methods, as I’ve always done in Smalltalk, and then if performance is a problem, I can worry about inlining them, and potentially even using decorators to inline them for me. This is a further step on my road to stop optimizing before I understand the problem.
This entry was posted at 3:37 pm on 7 December 2004 and is filed under Python. You can follow any responses to this entry through the post-specific RSS 2.0 feed.
I disagree. For example, I have a method which builds up a data structure from some input. It has a lot of stages that it goes through linking it together, and to do that all in init would be silly. Honestly, I think different people have different approaches, but I find that if I can hide certain things, the overall logic becomes much more obvious.
Both comments and pings are currently closed.
I think you are interpreting more intention behind this than actually exists.
Python tends to be more imperative than Smalltalk, which leads to more lines. And a single method can serve many purposes given different keyword arguments, which isn’t what you’d do in Smalltalk; a set of methods in Smalltalk often becomes one almost completely equivalent Python method.
The UI probably is to blame as well. Methods are very distinct units in Smalltalk, but a little more vague in a file. If three things are always executed in sequence, it’s a little annoying in Python if it’s three methods.