[Tutor] Simple code (was: Dumb Subclassing question)
alan.gauld at blueyonder.co.uk
Fri Aug 6 08:34:07 CEST 2004
> >On a final note, it should be realised that OOP does not
> >automatically imply writing less code. In fact for short programs
> I think good programming practice often does imply writing less
> two reasons. One is the DRY principle - Don't Repeat Yourself. In
> words don't copy/paste identical sections of code. Don't duplicate
Yes but the reason OOP results in more code for short programs is that
there is a minimum amount of scaffolding involved in creating classes
etc in the first place!
> Second is YAGNI - You Aren't Gonna Need It -- which is closely
> "Do the simplest thing that could possibly work."
But simplest is not necessarily shoirtest. Short code is often very
This thread is a good example. While the overridden constructor
neat and results in less code, it will be far more difficult to
if it turns out later to be unsuitable. The simple solution is just to
override the methods or create a new convertion function - more work
> These two principles of Extreme Programming are generally useful.
They are sometimes useful. :-)
XP has many limitations as well as advantages.
> One of the great things about Python is that you can write short
> without cluttering them up with needless OO complexity.
Absolutely, use OOP where it is appropriate but if writing a hello
print "hello World"
is better than an OOP solution!
> I'm all in favor of maintainable and robust code. I generally try to
> the flexibility until I actually need it. Simple is good.
Sure, and one of the aims of OOP is to provide flexibility for free.
You can extend a class without changing the original and therefore
without incurring a roisk of breaking existing code.
Of course for this to work properly the classes need to be designed
well to sart with - no side effects etc.
More information about the Tutor