"no variable or argument declarations are necessary."

Antoon Pardon apardon at forel.vub.ac.be
Tue Oct 4 06:16:37 EDT 2005


Op 2005-10-04, Steven D'Aprano schreef <steve at REMOVEMEcyber.com.au>:
> Mike Meyer wrote:
>
>> Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
>> 
>>>Declared variables have considerable labour costs, and only marginal
>>>gains. Since the steps you take to protect against other errors will also
>>>protect against mistyping variables, declarations of variables is of
>>>little practical benefit.
>> 
>> 
>> As far as I can tell, this is as much hearsay and personal experience
>> as the alternate claim that not having them costs you lots of
>> debugging time and errors. If anyone has pointers to real research
>> into this area (I've heard the TRAK folks did some, but haven't been
>> able to turn any up), I'd love to hear it.
>
> Sorry, I have no hard research to point to. If I did, I 
> would have referenced it.
>
>> My gut reaction is that it's a wash. The time taken to declare
>> variables in well-written code in a well-designed language - meaning
>> the declarations and use will be close together - isn't all that
>> great, but neither are the savings.
>
> It isn't the typing time to declare variables, it is 
> the context switching. You're focused on implementing 
> an algorithm, realise you need to declare another 
> variable, your brain does a mini-context switch, you 
> scroll up to the declaration section, you declare it, 
> you scroll back to where you were, and now you have to 
> context switch again.
>
> You've gone from thinking about the implementation of 
> the algorithm to thinking about how to satisfy the 
> requirements of the compiler. As context switches go, 
> it isn't as big as the edit-compile-make-run method of 
> testing, but it is still a context switch.
>

Nobody forces you to work this way. You can just finish
your algorithm and declare your variables afterwards.

Besides likewise things can happen in python. If you
suddenly realise your class needs an instance variable,
chances are you will have to add initialisation code
for that instance variable in the __init__ method.
So either you do a context switch from implementing
whatever method you were working on to the initialisation
in __init__ and back or you just code without 
initialisation, intending to go back an do it later.

> Or you just code without declaring, intending to go 
> back and do it later, and invariably forget.

What's the problem, the compilor will allert you
to your forgetfullness and you can then correct
them all at once.

-- 
Antoon Pardon



More information about the Python-list mailing list