Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20187 > unrolled thread

How can I catch misnamed variables?

Started byJohn Gordon <gordon@panix.com>
First post2012-02-10 21:06 +0000
Last post2012-02-11 00:21 +0100
Articles 7 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  How can I catch misnamed variables? John Gordon <gordon@panix.com> - 2012-02-10 21:06 +0000
    Re: How can I catch misnamed variables? Arnaud Delobelle <arnodel@gmail.com> - 2012-02-10 21:17 +0000
    Re: How can I catch misnamed variables? Kev Dwyer <kevin.p.dwyer@gmail.com> - 2012-02-10 21:22 +0000
    Re: How can I catch misnamed variables? Ben Finney <ben+python@benfinney.id.au> - 2012-02-11 08:26 +1100
      OT (waaaayyyyyyyyy off-topic) [was Re: How can I catch misnamed variables?] Ethan Furman <ethan@stoneleaf.us> - 2012-02-10 13:56 -0800
        Re: OT (waaaayyyyyyyyy off-topic) Ben Finney <ben+python@benfinney.id.au> - 2012-02-11 09:45 +1100
    Re: How can I catch misnamed variables? Christian Heimes <lists@cheimes.de> - 2012-02-11 00:21 +0100

#20187 — How can I catch misnamed variables?

FromJohn Gordon <gordon@panix.com>
Date2012-02-10 21:06 +0000
SubjectHow can I catch misnamed variables?
Message-ID<jh40ti$t3i$1@reader1.panix.com>
Recently I was been bitten by some stupid errors in my code, and I'm
wondering if there's a simple way to catch them.

One error was of the form:

  my_object.some_function()

.. when I hadn't declared an object named "my_object".

The other error was similar:

  x = my_module.CONSTANT

.. when I hadn't imported my_module.

Of course both of these errors were deep inside a long-running function
call, so it took a while for them to crop up.

Is there an automated way to catch errors like these?  I'm using the
compileall module to build my program and it does catch some errors
such as incorrect indentation, but not errors like the above.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [next] | [standalone]


#20188

FromArnaud Delobelle <arnodel@gmail.com>
Date2012-02-10 21:17 +0000
Message-ID<mailman.5678.1328908625.27778.python-list@python.org>
In reply to#20187
On 10 February 2012 21:06, John Gordon <gordon@panix.com> wrote:
> Recently I was been bitten by some stupid errors in my code, and I'm
> wondering if there's a simple way to catch them.
>
> One error was of the form:
>
>  my_object.some_function()
>
> .. when I hadn't declared an object named "my_object".
>
> The other error was similar:
>
>  x = my_module.CONSTANT
>
> .. when I hadn't imported my_module.
>
> Of course both of these errors were deep inside a long-running function
> call, so it took a while for them to crop up.
>
> Is there an automated way to catch errors like these?  I'm using the
> compileall module to build my program and it does catch some errors
> such as incorrect indentation, but not errors like the above.

There's pychecker and pylint

-- 
Arnaud

[toc] | [prev] | [next] | [standalone]


#20189

FromKev Dwyer <kevin.p.dwyer@gmail.com>
Date2012-02-10 21:22 +0000
Message-ID<mailman.5679.1328909007.27778.python-list@python.org>
In reply to#20187
John Gordon wrote:

> Recently I was been bitten by some stupid errors in my code, and I'm
> wondering if there's a simple way to catch them.
> 
<snip>


Pyflakes is another static checker that can catch these sorts of errors.

Cheers,

Kev 

[toc] | [prev] | [next] | [standalone]


#20191

FromBen Finney <ben+python@benfinney.id.au>
Date2012-02-11 08:26 +1100
Message-ID<87vcne2xee.fsf@benfinney.id.au>
In reply to#20187
John Gordon <gordon@panix.com> writes:

> Is there an automated way to catch errors like these?

Use a static code checker, such as ‘pyflakes’ (simple but limited) or
‘pylint’ (complex but highly configurable) to catch these and many other
problems in Python code.

-- 
 \          “It's a terrible paradox that most charities are driven by |
  `\     religious belief.… if you think altruism without Jesus is not |
_o__)          altruism, then you're a dick.” —Tim Minchin, 2010-11-28 |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#20196 — OT (waaaayyyyyyyyy off-topic) [was Re: How can I catch misnamed variables?]

FromEthan Furman <ethan@stoneleaf.us>
Date2012-02-10 13:56 -0800
SubjectOT (waaaayyyyyyyyy off-topic) [was Re: How can I catch misnamed variables?]
Message-ID<mailman.5683.1328912317.27778.python-list@python.org>
In reply to#20191
Ben Finney wrote (from signature):
 > “It's a terrible paradox that most charities are driven by religious
 > belief. . . . if you think altruism without Jesus is not altruism,
 > then you're a dick.” —Tim Minchin, 2010-11-28

1) Why is it paradoxical?  If anything it's a sad commentary on those 
who don't ascribe to a religion, as it would appear that they care less 
for their society.

2) altruism: unselfish regard for or devotion to the welfare of 
others... no mention of religion of any kind, or Jesus in particular.

Altruistic-yet-paradoxically-religious-ly yours,
~Ethan~

[toc] | [prev] | [next] | [standalone]


#20200 — Re: OT (waaaayyyyyyyyy off-topic)

FromBen Finney <ben+python@benfinney.id.au>
Date2012-02-11 09:45 +1100
SubjectRe: OT (waaaayyyyyyyyy off-topic)
Message-ID<87mx8q2tpz.fsf@benfinney.id.au>
In reply to#20196
Thanks for responding. Rather than take this discussion too far where
it's quite off-topic, I'll respond briefly and ask for a change of forum
if we want to continue.


Ethan Furman <ethan@stoneleaf.us> writes:

> Ben Finney wrote (from signature):
> > “It's a terrible paradox that most charities are driven by religious
> > belief. . . . if you think altruism without Jesus is not altruism,
> > then you're a dick.” —Tim Minchin, 2010-11-28

The quote is from an interview with Tim Minchin
<URL:http://www.guardian.co.uk/stage/2010/nov/28/tim-minchin-comedian>.

> 1) Why is it paradoxical? If anything it's a sad commentary on those
> who don't ascribe to a religion, as it would appear that they care
> less for their society.

It's an outcome of history that religious institutions have historically
been well-situated to be the facilitators of charitable work (and much
other work) simply because they have been ubiquitous in most societies.
The paradox is that they spend much of their resources away from the
worldly, i.e. secular, work of charity.

But charitable work is not dependent on religious belief, and indeed in
recent decades there are now a great many wholly secular charities (e.g.
International Red Cross and Oxfam) which do not divert their resources
from addressing the real world.

> 2) altruism: unselfish regard for or devotion to the welfare of
> others... no mention of religion of any kind, or Jesus in particular.

Yes, that's the point. Altruism is a human activity independent of
religious belief, yet the default assumption of too many is that they
are somehow necessarily connected.

> Altruistic-yet-paradoxically-religious-ly yours,

As you rightly point out, this discussion is off-topic here. So while
I'm open to discussion on this topic, we should move it to some other
forum.

-- 
 \        “Most people, I think, don't even know what a rootkit is, so |
  `\     why should they care about it?” —Thomas Hesse, Sony BMG, 2006 |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#20205

FromChristian Heimes <lists@cheimes.de>
Date2012-02-11 00:21 +0100
Message-ID<mailman.5688.1328916091.27778.python-list@python.org>
In reply to#20187
Am 10.02.2012 22:06, schrieb John Gordon:
> Is there an automated way to catch errors like these?  I'm using the
> compileall module to build my program and it does catch some errors
> such as incorrect indentation, but not errors like the above.

Write unit tests and use coverage to aim for 100% code and branch coverage.

If you want to write high quality code and avoid problems like misnamed
variables then you have to write unit tests and functional tests for
your program. I'm well aware that it's hard and requires time. But in
the long run it will *save* lots of time.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web