Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Phred (5358)

Phred
  fredNO@SPAMtaperfriendlymusic.org
http://www.redhotpenguin.com/

Fred is a Perl and PostgreSQL geek. He has made some very small contributions to a few cpan modules and mod_perl.

Journal of Phred (5358)

Wednesday August 15, 2007
03:19 PM

$DEBUG and commented out code

[ #34121 ]

Sometimes I come across code that is commented out (everyone has right?). The immediate question that comes to mind is what is the reason for the comments.

Sometimes it's obvious, like a really verbose debugging statement that you don't want to use often. Other times it's less obvious. One time I asked the author why a particular piece of code was commented out, and he said "Well I wrote it and then found a better way but I didn't want to throw the old code away. We might want to reuse that code someday, but don't move it because we'll lose track of it". Gah :)

So now when I have a piece of really verbose debugging code, I put

our $DEBUG = 1;

as a global, and use that to trigger the debugging. I also use

our $LEGACY = 1;

to mark old sections of code with conditionals. It's easier than dealing with the social politics of where unused code should go, and gives the maintainer some hint of why this code is there.

 

Try removing someone's old commented out code and then see how they react when the commit message comes through - trust me this is a better approach. I even used to leave my own commented code in places, and after coming back to it I remember the fear of "ok will this module blow up if I uncomment this?", or something similar. I can't take credit for this idea, I picked it up from working with another great coder.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • ... so at least it's compiled out :/
  • Why not just put a textual comment with the commented code explaining why it's commented out. Not only will it not be compiled in, but it will also have a nice long explanation about why it's not being used.

    You can even make a reference to a co-worker's hissy fit that occurred when you deleted it :)
    • I use this approach probably 90% for verbose debugging and 10% to wrap scary looking code. I try to comment scary code sometimes, but most often what I see is

        $foo->method_makes_sense;
        # $foo->mugwumpus;
        $foo->save;
      so then I have to go and figure out what mugwumpus() does, which involves grepping, and emailing. I guess I'd rather spend my time coding than mugwumpus-spelunking :)