Does Python really follow its philosophy of "Readability counts"?

Chris Rebert clp2 at rebertia.com
Sun Jan 11 18:49:31 EST 2009


On Sun, Jan 11, 2009 at 3:15 PM, Carl Banks <pavlovevidence at gmail.com> wrote:
> On Jan 11, 3:31 pm, Chris Rebert <c... at rebertia.com> wrote:
>> On Sun, Jan 11, 2009 at 1:22 PM, Madhusudan.C.S <madhusuda... at gmail.com> wrote:
>> >    def somemethod(self, arg1):
>> >        self.c = 20.22
>> >        d = "some local variable"
>> >        # do something
>> >        ....
>> >    ...
>> >    def somemethod2 (self, arg2):
>> >        self.c = "Changed the variable"
>> >        # do something 2
>> >        ...
>>
>> > In such situations, where the Instance variables come into existence
>> > only when they are used
>> > it is very difficult to track the flow of code. Its obviously not
>> > possible to remember what
>> > instance variable was defined where, when reading some substantial
>> > amount of code and where
>> > it was manipulated for that matter. It becomes so very frustrating
>> > even when reading a Class's
>> > code with just 6-8 methods and not more than 100-150 lines of code.
>>
>> That's bad coding style on the part of the code writer.
>> Conditionally-existing instance variables are *evil*.
>
>
> Do you mean conditionally-useful instance variables evil, or that
> conditionally-useful variables are ok but it's evil for them to
> conditionally-exist?
>
> The former I don't agree with at all.
>
> If it's the latter, I believe there is something to be said for
> variables that exist when they are needed and don't when they're not.
> However, I acknowledge that listing all the variables you intend to
> use in __init__ is highly comforting, even if it does belie their
> current uselessness.

The latter. I never even used the word "useful", so I have no idea
where you got that from.
To reiterate, variables which might only exist under certain
conditions are evil, IMHO.
This is not to say they are not useful in certain specific cases, just
that in general there are better ways to design/structure programs to
avoid them.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list