<div dir="ltr">Some thoughts:<div><br></div><div>1. I too dislikes the idea of using comments as semantically significant annotations.</div><div><br></div><div>I think it's quite OK for annotation that are aimed at external tools (e.g. '# nocover' or '# noqa') but not for runtime behavior.</div><div><br></div><div>2. It's probably possible do do interesting things using decorators at the function / class level.</div><div><br></div><div>The "q" project (<a href="https://pypi.python.org/pypi/q">https://pypi.python.org/pypi/q</a>) already does some useful things in that direction.</div><div><br></div><div>Still, when using q (or another decorator-based approach), you need to first 'import q', which means that you can easily end up with spurious 'import q' in your code, after you're done debugging. Or even worse, commit them but forget to add 'q' in your setup.py / requirements.txt / Pipfile, and break CI or production.</div><div><br></div><div>3. Doing things unintrusively at the statement level seems much harder.</div><div><br></div><div>  S.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 25, 2018 at 6:54 AM, Steve Barnes <span dir="ltr"><<a href="mailto:gadgetsteve@live.co.uk" target="_blank">gadgetsteve@live.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 24/01/2018 23:25, Larry Yaeger wrote:<br>
> Everyone uses logging during code development to help in debugging.  Whether using a logging module or plain old print statements, this usually requires introducing one or (many) more lines of code into the model being worked on, making the existing, functional code more difficult to read.  It is also easy to leave logging code in place accidentally when cleaning up.  I have a possibly odd suggestion for dramatically improving debug logging, in an almost automated fashion, without any of the usual problems.  I'm willing to jump through PEP hoops, but won't waste anyone's time arguing for the idea if others don't embrace it.<br>
><br>
> In brief, make an extremely succinct comment, such as "#l" or "#dbgl", semantically meaningful.  If appended to a line of code, such as:<br>
><br>
> x = 1<br>
> Y = 2<br>
> Z = 3<br>
> x = y + z  #l<br>
><br>
> When executed the line would be logged (presumably to stdout) as something like:<br>
><br>
> x=1 -> y=2 + z=3 -> 5<br>
><br>
> In one log line you see the variables and their values, the operations being performed with them, and the result of the evaluated expression.<br>
><br>
> Placing "#l" on a def Function() line would apply "#l" logging to every line in that function or method.<br>
><br>
> That's it.  Adding these log requests would be easy and not clutter the code.  Removing them reliably would be a trivial global operation in any text editor.  The resulting debug information would be fully diagnostic.<br>
><br>
> Of course there are lots of details and edge cases to consider.  There always are.  For example, what if x had not been previously defined?  A reasonable answer:<br>
><br>
> x=. -> y=2 + z=3 -> 5<br>
><br>
> In every case the solution should minimize volume of output while maximizing logged information.<br>
><br>
> One can debate the precise formatting of the output.  The text used for the semantically meaningful comment string is open to debate.  The output pipe could be made controllable.  There are natural extensions to allow periodic and conditional logging.  I have ideas for reducing (already unlikely) collisions with existing comments.  But I want to keep this simple for now, and I think this captures the core of the idea.<br>
><br>
> For your consideration.<br>
><br>
> - larryy<br>
> ______________________________<wbr>_________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
</span>> <a href="https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas&data=02%7C01%7C%7C1833282b2db342f6476308d563825af0%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636524333870912999&sdata=K5Qd3iat2NG4h%2F1rgIf4C9FOmv8%2Fa%2FUN23I3jOiW0PU%3D&reserved=0" rel="noreferrer" target="_blank">https://eur02.safelinks.<wbr>protection.outlook.com/?url=<wbr>https%3A%2F%2Fmail.python.org%<wbr>2Fmailman%2Flistinfo%2Fpython-<wbr>ideas&data=02%7C01%7C%<wbr>7C1833282b2db342f6476308d56382<wbr>5af0%<wbr>7C84df9e7fe9f640afb435aaaaaaaa<wbr>aaaa%7C1%7C0%<wbr>7C636524333870912999&sdata=<wbr>K5Qd3iat2NG4h%2F1rgIf4C9FOmv8%<wbr>2Fa%2FUN23I3jOiW0PU%3D&<wbr>reserved=0</a><br>
> Code of Conduct: <a href="https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F&data=02%7C01%7C%7C1833282b2db342f6476308d563825af0%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636524333870912999&sdata=TcZ2QLkZ0rDntMEQvouNFFnzn7HBBBT64cb%2ByrdIDj8%3D&reserved=0" rel="noreferrer" target="_blank">https://eur02.safelinks.<wbr>protection.outlook.com/?url=<wbr>http%3A%2F%2Fpython.org%2Fpsf%<wbr>2Fcodeofconduct%2F&data=02%<wbr>7C01%7C%<wbr>7C1833282b2db342f6476308d56382<wbr>5af0%<wbr>7C84df9e7fe9f640afb435aaaaaaaa<wbr>aaaa%7C1%7C0%<wbr>7C636524333870912999&sdata=<wbr>TcZ2QLkZ0rDntMEQvouNFFnzn7HBBB<wbr>T64cb%2ByrdIDj8%3D&reserved=0</a><br>
><br>
<br>
I thing that this idea has some merit, obviously with some details to be<br>
worked out as well.<br>
<br>
I would suggest, however, that if this feature is introduced it be<br>
controlled via a run-time switch &/or environment variable which<br>
defaults to off. Then rather than the developer having to do global<br>
replaces they simply turn off the switch (or reduce it to zero).<br>
<br>
It may also be preferable to use decorators rather than syntactically<br>
significant comments, (personally I don't like the latter having had too<br>
many bad experiences with them).<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Steve (Gadget) Barnes<br>
Any opinions in this message are my personal opinions and do not reflect<br>
those of my employer.<br>
</font></span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Stefane Fermigier - <a href="http://fermigier.com/" target="_blank">http://fermigier.com/</a> - <a href="http://twitter.com/sfermigier" target="_blank">http://twitter.com/sfermigier</a> - <a href="http://linkedin.com/in/sfermigier" target="_blank">http://linkedin.com/in/sfermigier</a><br>Founder & CEO, Abilian - Enterprise Social Software - <a href="http://www.abilian.com/" target="_blank">http://www.abilian.com/</a><br>Chairman, Free&OSS Group / Systematic Cluster - <a href="http://www.gt-logiciel-libre.org/" target="_blank">http://www.gt-logiciel-libre.org/</a><br>Co-Chairman, National Council for Free & Open Source Software (CNLL) - <a href="http://cnll.fr/" target="_blank">http://cnll.fr/</a><div>Founder & Organiser, PyData Paris - <a href="http://pydata.fr/" target="_blank">http://pydata.fr/</a><br></div><div>---</div><div><div>“You never change things by fighting the existing reality. To change something, build a new model that makes the existing model obsolete.” <span style="font-size:12.8px">— R. Buckminster Fuller</span></div></div><div><br><br></div></div></div></div></div></div></div></div>
</div>