Re:1-star reviews of 'Extreme Programming'
by dbarlett on Thursday December 19, 2013 @12:26PM
(#6936130)
Example from real-world code I've written:
if tag in tag_list:
data[u"Tag"] = tag
try:
if i["DupilcateAssets"] is not None: # not a typo - misspelled in Dell SOAP response
data[u"Error"] = "Duplicate assets returned"
Would you want to debug that without the comment?
Re:1-star reviews of 'Extreme Programming'
by raverbashing on Thursday December 19, 2013 @05:52PM
(#6938550)
This is a great example of a comment that should (or even must) be there.
If something doesn't work the way it should and it's beyond your control, comment it.
Re:1-star reviews of 'Extreme Programming'
by mpweiher on Thursday December 19, 2013 @12:45PM
(#6936258)
Gladly:
sillyMisspelledDellSOAPIdentifier = "DupilcateAssets"
if i[sillyMisspelledDellSOAPIdentifier] is not None:
Re:1-star reviews of 'Extreme Programming'
by dded on Thursday December 19, 2013 @01:42PM
(#6936731)
But this is largely a comment disguised as a variable name, and is no more or less likely to stay up-to-date as a comment. If the Dell Identifier were to ever be changed to "DuplicateAssets", you're just as likely to have
sillyMisspelledDellSOAPIdentifier = "DuplicateAssets"
as the original might have if i["DuplicateAssets"] is not None: # Not a typo...
And your method replaces one line of code with two.Comments have problems, but they solve problems too. They're not evil.
Agreed - I'd really appreciate coming across that one. It probably isn't the definitive example I'm looking for though.
Re:1-star reviews of 'Extreme Programming'
by aerique on Thursday December 19, 2013 @02:06PM
(#6936959)
Why not just:
if i["DupilcateAssets"]
is there some Python subtlety I am missing?In python some things evaluate as false in an if or boolean conversion (0, an empty list/tuple/set/dict/user_defined, an empty string "", and more). None evaluates as false as well, but is still distinguishable from the rest.
In ruby you likewise sometimes need to use object.nil? because nil and False are both "false-ish".
Re:1-star reviews of 'Extreme Programming'
by jheriko on Thursday December 19, 2013 @01:00PM
(#6936362)
some comments are very useful, this is a great example
Re:1-star reviews of 'Extreme Programming'
by MartinCron on Thursday December 19, 2013 @12:11PM
(#6935977)
I tend to have the "comments are an apology" mindset, where I will write a comment to apologize if something is partially implemented, counter-intuitive, driven by a byzantine external requirement, or an ugly workaround to someone else's bug.
Those can totally be essential, as they will save someone (your future self, maybe) from attempting to refactor them to something simpler/cleaner that won't actually work.
Edit: Not project documentation, strictly code comments.