4 ms·
Is this any different from the comment style: a = 1 # set variable a to 1 a += 1 # add 1 to a ? Comments should explain the why, not the what. `\d
by jodrellblank 6y ago
Is this any different from the comment style:
a = 1 # set variable a to 1
a += 1 # add 1 to a
?
Comments should explain the why, not the what. `\d # digit` yes that is what it says, but why a digit? What is your ^, what is (?:) what is $, why is (?:[^\ ]) "rest of URL" [I know the answers to these, the person the comments are intending to help probably doesn't]. Where's the explanation of what it's supposed to be doing with a limited subset of URLs?
# match basic URLs such as:
# http://example.org
# https://www.example.org
# Must have no surrounding spaces, no spaces in the text.
^(?:http)(?:s)?(?:\:\/\/)(?:www\.)?(?:[^\ ]*)$
It's much clearer to me from the one-line regex that it matches "http:////////// http://////////" and that's probably an error. I don't know why it's clearer, maybe because I'm used to looking at
https://www.example.org/path/
instead of
https
://
www.
example.org/path/
- stickfigure 6y agoMostly we program in languages that read like a kind of shorthand english, and mature programmers are expected to be able to read the text fluently. WHAT comments tend to be superfluous. Nobody sane reads 100+ character regexes fluently, so WHAT comments are totally appropriate. Any time I write a nontrivial regular expression, I always try leave an example of what it would match in a comment. I've thanked last-year me for this more times than I can count.