I mostly write small scripts in python, about 50 – 250 lines of code. I usually don’t use any objects, just straightforward procedural programming.
I know OOP basics and I have used object in other programming languages before, but for small scripts I don’t see how objects would improve them. But maybe that is just my limited experience with OOP.
Am I missing something by not trying harder to use objects, or does OOP just not make a lot of sense for small scripts?
I use whatever paradigm best suits the issue at hand — be it procedural, OOP, functional, … program size is not a criterion, though (by a little margin) a larger program may be more likely to take advantage of OOP’s strengths — multiple instances of a class, subclassing and overriding, special method overloads, OOP design patterns, etc. Any of these opportunities can perfectly well occur in a small script, there’s just a somewhat higher probability that it will occur in a larger one.
In addition, I detest the
globalstatement, so if the natural procedural approach would require it, I will almost invariably switch to OOP instead — even if the only advantage is the ability to use a qualified name instead of the barename which would requireglobal.There’s definitely no need to “try harder” in general — just ask yourself “is there an opportunity here to use (a) multiple instances (etc etc)” and it will soon become second nature, i.e., you’ll spot the opportunities without needing to consciously remind yourself every time to look for them, and your programming will improve as a result.