Debugging (was Re: Why not allow empty code blocks?)

Chris Angelico rosuav at gmail.com
Tue Aug 2 15:18:50 EDT 2016


On Wed, Aug 3, 2016 at 3:57 AM, Steven D'Aprano
<steve+python at pearwood.info> wrote:
> On Wed, 3 Aug 2016 03:12 am, BartC wrote:
>
>> That's not a fundamental language feature. Repeat-N is. And if properly
>> designed, isn't an extra feature at all but a special case of a generic
>> loop.
>
> Which means it is NOT a fundamental language feature.
>
> "Repeat N without tracking the loop variable" is just a special case
> of "repeat N with tracking the loop variable", where you don't actually
> care what the loop variable is.

To be fair, that can be an important distinction. I don't like seeing
code like this:

def f():
    x = g()
    y = h(x)
    return 5 + x

What's y for? Why not just call h(x) and ignore its return value?
Should the last line say "5 + y"? It looks _wrong_ to have a local
variable that's never used. It's still not a consideration strong
enough to demand new loop syntax, though.

ChrisA



More information about the Python-list mailing list