in reply to Re: A refactoring trap
in thread A refactoring trap
If I want to comment the regex, I'd write:my $tmp = 0; # Make $tmp 0. $i ++; # Increment $i. print "hello"; # Print 'hello' to the screen.
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 what's between brackets, # omitting leading white space. /\[\s*([^\]]+)/;
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.# Capture the wiki-link. /\[\s*([^\]]+)/;
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: A refactoring trap
by Nkuvu (Priest) on Aug 17, 2005 at 16:55 UTC |