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.
Re:comments?
Phred on 2007-08-16T17:54:11
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
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$foo->method_makes_sense;
# $foo->mugwumpus;
$foo->save;:)