Those things are better explained in a comment, I'd think.
Comments are needed, but should not explain what the code does (as in "add 1 to n") and instead exaplin why it does it (as in "fn expects indices to start from 1").
Those things are better explained in a comment, I'd think.
Comments are needed, but should not explain what the code does (as in "add 1 to n") and instead exaplin why it does it (as in "fn expects indices to start from 1").
It can and the code in question will print both "bright" and "light" if passed a color that matches that.
Where did you see that it's an either-or affair in the example?
Besides, the key point, is that the code talks about luminocity and brightness levels, and the second example makes that explicit. No comments needed if you know what HSV is. And if you don't, comments are usually not the place to learn about it.
if color.saturation > .5:
print("bright!")
elif color.luminosity > .5:
print("light!")
it's an `elif`... it will never print both "bright" and "light"This kind of mistake really detracts from the point that was argued here about code being "intelligible"
I didn't read it carefully here, as I had already seen the presentation and it wasn't until your disagreement I realized the code was different.
There's nothing wrong with if/elses, but I strongly prefer pattern matching, where available. And even more, I think it's important to keep computation and presentation separate... that is, to not entagle IO with the rest of the code.
(Unfortunately Haskell is the only language I know of that gives you a tool to tackle that)
Obviously this was just a small example, but I've seen unintended IO byte back the developer in real world (Python) code.
And another small comment: since I haven't bothered to comment on Hettinger's talk before now.
I liked it (but played it back at 1.5x)... but since it's not first talk by Raymond Hettinger I saw, I knew that his delivery is good. Some of the stuff (should?) be obvious to every (Python) developer (but repetita juvant). I didn't like the jab at Java for the mistake of iterating over indexes: there's no excuse to writing that code not even there (look at the Iterator and Iterable interfaces)
$ python
>>> if True:
... print "First"
... elif True:
... print "Second"
...
First
>>>That's not the code in his example. Here's that code:
Yeah, didn't pay close attention to it, thought it was the same as the one I saw in the presentation.