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

BartC bc at freeuk.com
Tue Aug 2 07:05:51 EDT 2016


On 31/07/2016 19:58, Terry Reedy wrote:
> On 7/31/2016 6:18 AM, BartC wrote:

>>  repeat N:

>> The benefit is not so much performance, but being able to express
>> something very easily and quickly.
>
> The cost of the 'repeat' contraction is that one cannot use the loop
> variable, either as part of a modified computation or for monitoring or
> debugging purposes.
>        print(i, for_body_result)
> Beginners are often atrocious at debugging, and it seems not to be
> taught hardly at all.  'repeat n' erects a barrier to debugging.

> Debugging: probing a computation to see what actually happens, as
> opposed to what one wanted and expected to happen.  (Me, just now ;-)
>
> One major way of debugging is printing values as they are computed.
> Naming values (objects) allows them to be printed without recomputing
> the value.  In the 'repeat n' context, recomputing would mean adding 3
> lines of debugging code instead of 1.
>
> i = 0
> repeat n:
>    a = f(a)
>    print(i, a)
>    n += 1

Your objection to a feature such as 'repeat N' doesn't really stack up.

Debugging code is stuff that you add temporarily to find out what's 
going on, then you get rid of it to leave the clean, unfettered lines of 
the program.

You don't want people wondering where that loop index may or may not be 
used.

Anyway, if that was a valid objection, it would apply throughout the 
language. In list-comps for example (there is an index, but where do you 
stick the print?). Or in a for-loop iterating over values:

  a=[10,20,30,40,50]
  for x in a:
     print (x)

This will print the element, but what's the index? According to you, 
every such for-loop needs to be written in a form that provides the 
index of a loop, on the off-chance that someone might want to print its 
value somewhere in the body! ('for (i,x) in enumerate(a):')

I get that people here don't want such a feature, but I don't think this 
is the reason.

I think the real reason is not willing to admit that the language lacks 
something that could actually be useful, and especially not to an 
upstart on usenet who is not even an expert in that language.

-- 
Bartc




More information about the Python-list mailing list