[Tutor] Simple code (was: Dumb Subclassing question)

Alan Gauld 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
code, for
> two reasons. One is the DRY principle - Don't Repeat Yourself. In
other
> words don't copy/paste identical sections of code. Don't duplicate
data.

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
related to
> "Do the simplest thing that could possibly work."

But simplest is not necessarily shoirtest. Short code is often very
complex.
This thread is a good example. While the overridden constructor
technique is
neat and results in less code, it will be far more difficult to
refactor
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
but
simpler code.

> 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
programs
> without cluttering them up with needless OO complexity.

Absolutely, use OOP where it is appropriate but if writing a hello
world

print "hello World"

is better than an OOP solution!

> I'm all in favor of maintainable and robust code. I generally try to
omit
> 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.

Alan G.



More information about the Tutor mailing list