A desperate lunge for on-topic-ness

Roy Smith roy at panix.com
Mon Oct 22 08:29:07 EDT 2012


In article <5084e819$0$29897$c3e8da3$5496439d at news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> On Mon, 22 Oct 2012 07:22:18 +1100, Chris Angelico wrote:
> 
> > On Mon, Oct 22, 2012 at 6:11 AM, Steven D'Aprano
> > <steve+comp.lang.python at pearwood.info> wrote:
> 
> >>> Ahh. I totally didn't see that, I'm way too used to reading past
> >>> typos.
> >>
> >> As a programmer, doesn't that screw up your debugging ability?
> > 
> > Reading-past-typos applies mainly to English, which is a pretty
> > redundant language. In code, it would only apply to variable names; with
> > (effectively) single words/tokens standing alone, the automatic
> > correction doesn't really apply. But yes, sometimes I have stared at a
> > piece of code for a long time without knowing why there's an error on
> > line X. (This is another good reason to require that all variables be
> > declared, incidentally. I might have a variable called "source" but not
> > "souce", so using the other causes an instant compile-time failure on
> > the exact line with the bug.)
> 
> "Another" good reason?
> 
> For languages without static types, what other reasons for declaring 
> variables are there?

Variable declarations serve two purposes.  One is to declare the type 
(which obviously doesn't apply to Python).  The other is to declare the 
beginning of a scope.

On occasion, I will make typos in variable names which a 
scope-introduction declaration would have prevented.  If the cost of 
having to declare every variable would be justified by the rare bug it 
would prevent, is another question.

Pet peeve of the day...

Why do you have to write:

global foo
foo = 4

when

global foo = 4

would have been so much easier?



More information about the Python-list mailing list