How to write good Python objects?

John Roth newsgroups at jhrothjr.com
Fri Oct 24 06:31:21 EDT 2003


"John Ladasky" <ladasky at my-deja.com> wrote in message
news:c09b237b.0310231715.2e1a6bc at posting.google.com...
> Hi, folks,
>
> At the beginning of 2003, I was a frustrated computer user, and lapsed
> programmer, with problems to solve that screamed for programming.
> Thanks to the Python language and community, I am a programmer once
> again.
>
> My earlier solicitation to the computer world is here:
>
>
http://groups.google.com/groups?selm=c09b237b.0302060136.5683054e%40posting.google.com
>
> Anyway, I've been busy with Python for several months now.  I'm an old
> procedural guy.  I had never written code in an object-oriented
> language before.  I'm starting to get the hang of it, and to see its
> advantages, but I'm still struggling.  I think that I have issues with
> both OOP in general, and with Python in particular.
>
> I have written one nice, self-contained object that contained a DNA
> sequence, and various functions to manipulate the data therein.  My
> wxPython GUI objects, in contrast, are in a state of constant flux.
> Rather than importing and reusing a piece of code, I find myself
> copying the code into my new program and playing with it, just a bit.
> I'm starting to believe that writing a good GUI object, one that you
> can really reuse, is actually quite hard.  Yes, I know that you can
> derive a new object that overrides properties of your old object.
> Should I find myself doing this for every object that I write?

I'd suggest you look at refactoring out duplication. What it sounds like
is that you're generating a lot of minor variations on the same theme.
If you go after duplication relentlessly, eventually the code itself will
tell you what it wants to look like.


> Thanks for your advice!

You're welcome.

John Roth
>
> --
> John J. Ladasky Jr., Ph.D.
> Department of Biology
> Johns Hopkins University
> Baltimore MD 21218
> USA
> Earth






More information about the Python-list mailing list