13 Apr
2013
13 Apr
'13
11:07 p.m.
Peter Norvig wrote:
Beginners will often write code like this:
if val > 0: return +1 elif val < 0: return -1 elif val == 0: return 0
Here's an idea to address this. What do you think of the syntax
"else" expression ":"
This will do nothing to help said beginner. He will continue to write "elif val == 0:", blissfully unaware that there could be another case that he hasn't thought of. If he had the presence of mind to realise that, he would have written something safer in the first place. -- Greg