in reply to
Re: A refactoring trap
in thread A refactoring trap
Does it really gain that much? I think commenting out a regex like that is just as silly and pointless as writing:
my $tmp = 0; # Make $tmp 0.
$i ++; # Increment $i.
print "hello"; # Print 'hello' to the screen.
If I want to comment the regex, I'd write:
# Capture what's between brackets,
# omitting leading white space.
Because that documents the intent
of the regex, not the mechanics. Given the context, I'd probably even document what's between the brackets, and not just the fact I'm capturing between brackets, for instance:
# Capture the wiki-link.
Now, that's useful, and you immediately know what to change if the syntax of the wiki-links changes. Where as your example carefully documents the tiny steps it takes, and not the overall picture.
You might want to read Brian W. Kernighan, Rob Pike: The Practice of Programming, which discusses correct commenting style as well. And there's no reason to assume you should use a commenting style for regexes that's considered bad style for other code.