Erin Call

Erin Call

You Can't Spell Engineering Without Erin

Posts tagged harm reduction

Python's Scoping System Will Hurt You If You Let It

So, I ran into a bit of Python's behavior that upset me. Here's some code that is wrong:

if some_function():
    x = 5
print x

Depending on the return value of some_function, this code may or may not execute successfully. Whether or not it happens to succeed, though: it's wrong. You have this exception sitting there, waiting to jump up and bite you. It is a problem waiting to happen. Python doesn't care, though! It will happily accept that code and let you catch the error in production. But why? Why doesn't Python just define a new lexical scope when entering an if or for block? Then it could tell you during compile-time that your code is wrong, and you could fix it before it ever screwed you up.

(Read the full post...)

Posted on 2012-01-10T04:57:00Z
Posted in python, harm reduction.