On 01/04/2014 06:36 AM, Steven D'Aprano wrote:
Now, it's true that when *debugging code*, being able to see the name of
the variable and the contents of the variable is useful. But in ordinary
code, why would you care to print the name of the variable and its
contents. Who cares what the variable is named?

Debuggers stick all sorts of nasty hooks into the running interpreter in
order to do this (and much more), and we should all be thankful that (1)
debuggers exist, (2) that they aren't running by default, and most
importantly (3) that we don't have to write code like them.

In addition to powerful debuggers, we also have fantastic poor-man's
debugger called "print":

for name, value in zip(
             'alist blist clist'.split(), [alist, blist, clist]):
     print(name, "=", value)

I dream of a 'note' debug write function (or better statement with keyword, like assert) working like:

        n = 0
        i = 1
        note n          # ==> n = 1
        note i n        # ==> i = 0 | n = 1
        note i (type)   # ==> i = 0 (int)
        note i (where)  # ==> i = 0 (mod.cls.f, 333)

(The latter version gives full func name & line n° in module.)

I have always disliked debuggers, and REPL's as well (both too rigid & heavy), so maybe my view is somewhat marginal.

Yes, it's a little bit messy code. We have to repeat the name of the
variable twice. But this isn't code that will hang around in the
finished program. It only need exist for just long enough to debug the
problem we're having (you are having a problem, I presume?), then, it's
job done, it's gone.

You are right, but people who like exploratory, flexible, trial-and-error programming (even at tmes, not systematically), constantly write such debug statemetns or pieces of code, anew. (That's why I tend to let them code for a while; and I use a "write" debug func which just wraps print, just to have another name and be able to find & erase them all at once quickly.)

Denis
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to