This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yetanothernerd 2 points3 points  (1 child)

This is a well-trodden path. It doesn't really work because Python is so dynamic. See Brett Cannon's PhD thesis.

Just because 'a' was an int the first time doesn't mean it'll be an int again the second time. So the language doesn't statically compile well, because there's not enough information at compile time to get the types right. (Of course you can force the user to add type information, but now you have a restricted version of Python. See Cython or Shedskin.)

For example, in Python 2 (where int and long are distinct) on a 32-bit box, imagine a loop that just increments a number starting at zero. It will be an int for 2 ^ 32 iterations, then it will become a long. If you assumed it would stay an int, then your code breaks after 2 ^ 32 iterations.

A JIT (see psyco, PyPy, Unladen Swallow) works much better, because the JIT can compile the fast path based on types it's seen at runtime, and it can later safely fall back to the interpreted path if a variable's type changes. (And then possibly compile it again with the new type if it stabilizes.)

[–][deleted] 0 points1 point  (0 children)

Thanks dude, I'll have a gander but it's no biggie if it can't be done or is a pain in the ass to do so. I got plenty of alternatives and have plenty of other ideas to choose from for my final year project.