Programming

DWIM is consistent

Moshe Zadka has been writing a mostly excellent exploration of the Zen of Python for Opensource.com. Not sure I approve of this take on guessing, from The importance of consistency in your Python code:

What should the result of 1 + "1" be? Both "11" and 2 would be valid guesses. This expression is ambiguous: there is no single thing it can do that would not be a surprise to at least some people. Some languages choose to guess. In JavaScript, the result is "11". In Perl, the result is 2. In C, naturally, the result is the empty string. In the face of ambiguity, JavaScript, Perl, and C all guess.

Read more...

1 2 3