Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

To DEBUG, or to COMMENT. _That_ is the question

by taint (Chaplain)
on Nov 08, 2013 at 15:21 UTC ( #1061725=perlmeditation: print w/ replies, xml ) Need Help??

...Or are they the same, and this is all moot.

I tend to just poke around in the half-baked, or unfinished modules on CPAN, when I run into a problem on a Perl script/project I'm working on, and just can't seem to get past.

In doing so; I'll either come back with a fresh set of eyes. A light will go off, as I'm looking at someone elses code. Or I'll find a great Module to finish. Maybe even an idea for a better one.

In any case. I just ran into a Module by Damian Conway : Smart::Comments

While I have just now installed it. I haven't yet used it.
While it provides a number of other functions. It appears, for all practical purposes, that it would suffice as a pseudo DEBUGGER. Emitting errors thrown. Allowing to set "break points". Cobble up custom feedback at desired locations, yadda, yadda, yadda (gotta love Elaine, from Seinfeld, for that last bit).

Anyhow. I'm going to experiment with it, and see if it might just suffice as a mini/pseudo DEBUGGER. I only bothered, as it looks a bit eassier to implement, and use.

So I'm going to use this space to document my findings. So others that haven't heard of/used it, might find out more. For those that have, might share their experiences with it.

Well. That's it for now. If you have used this; please comment. Is this a practical pseudo DEBUGGER? No? Why not?

--Chris

#!/usr/bin/perl -Tw
use perl::always;
my $perl_version = (5.12.5);
print $perl_version;

Comment on To DEBUG, or to COMMENT. _That_ is the question
Re: To DEBUG, or to COMMENT. _That_ is the question
by boftx (Chaplain) on Nov 08, 2013 at 20:07 UTC

    I had some exposure to this recently. One of my colleagues was quite taken with it and has started to use it quite a bit, controlling it with a command line option.

    But another colleague, in the same shop, isn't fond of it inlining new code. There is also some thought that the loop comments don't play nice in a forked environment.

    Overall, I think it might be useful, especially for routine debugging messages, but I'm not sure I would want to use the loop reporting very often.

    The answer to the question "Can we do this?" is always an emphatic "Yes!" Just give me enough time and money.
      Greetings, boftx.

      As to the inlining new code, and loops; I can easily see where that'd be undesirable. I was mostly thinking in terms of "ferreting out" issues, and simply "tracing" the code/program/script.
      But then using perltidy to remove the extraneous comments, and such. Then unusing Smart::Comments before release. :)

      Best wishes

      --Chris

      #!/usr/bin/perl -Tw
      use Perl::Always or die;
      my $perl_version = (5.12.5);
      print $perl_version;
Re: To DEBUG, or to COMMENT. _That_ is the question
by Anonymous Monk on Nov 08, 2013 at 20:11 UTC
Re: To DEBUG, or to COMMENT. _That_ is the question
by sundialsvc4 (Monsignor) on Nov 08, 2013 at 22:10 UTC

    I have always wished for ... and, this being Perl so I’m sure it must exist I just don’t know of it ... an #if .. preprocessor capability, a la C/C++.   I would like “true conditional-compilation,” for any purpose including but not limited to the insertion of debugging code.   I am not familiar with this particular module enough to comment on its merits.   Certainly, these messaging techniques are crucial to the successful debugging and maintenance of production code ... whether done in this particular way or not.   Thanks for pointing out this module ... it seems well worth a closer look.

      How about the -P flag, as documented in perlrun (with a huge list of caveats)?

        The -P command-line switch was deprecated in perl version 5.10.0 and removed as of version 5.12.0 (see perl5120delta). But the equivalent behaviour is provided by the module Filter::cpp:

        #! perl use strict; use warnings; use Filter::cpp; #define DEBUG #define XYZ 42 #ifdef DEBUG print "Debugging enabled\n"; #else print "Debugging disabled\n"; #endif print XYZ . "\n";

        Output:

        13:14 >perl 772_SoPW.pl Debugging enabled 42 13:14 >

        See perlfilter.

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re: To DEBUG, or to COMMENT. _That_ is the question
by einhverfr (Monk) on Nov 16, 2013 at 15:34 UTC

    To be honest, I think something like Smart::Comments is downright dangerous. I have run into the anti-pattern of comments that do more than just sit there, and I have never ends well. While I understand these comments can just sit there. However, the idea of embedding programming logic in comments is something which brings back bad memories.

    More specifically it is way too easy to mistake a smart comment for a regular one or accidently write one. And it complicates reading comments. Good code is well documented with POD and sparsely commented but the comments themselves are an important part of the discourse about the code. One reads them and gets insight for why the programmer made this choice or that. One might explain why an unexpected structure exists, or why a given value is hardcoded. Adding a programming language to a subset of comments cannot help but interfere with that process. So comments as discussion about the code are valuable and this seems like it would dilute that value.

    For those reasons I would never use that module. I think debugging logic is always cleaner even if the instrumentation poses some overhead.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1061725]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (9)
As of 2014-07-14 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls