int/long unification hides bugs

Rocco Moretti roccomoretti at hotpop.com
Mon Oct 25 19:55:52 CEST 2004


kartik wrote:
> there seems to be a serious problem with allowing numbers to grow in a
> nearly unbounded manner, as int/long unification does: it hides bugs.
> most of the time, i expect my numbers to be small. 

The question is how small is small? Less than 2**7? Less than 2**15? 
Less than 2**31? Less than 2**63? And what's the significance of powers 
of two? And what happens if you move from a 32 bit machine to a 64 bit 
one? (or a 1024 bit one in a hundred years time?)

 > PEP 237 says, "It will give new Python programmers [...] one less
 > thing to learn [...]". i feel this is not so important as the quality
 > of code a programmer writes once he does learn the language.

The thing is, the int/long cutoff is arbitrary, determined soley by 
implemetation detail. A much better idea is the judicious use of assertions.

assert x < 15000

Not only does it protect you from runaway numbers, it also documents 
what the expected range is, resulting in a much better "quality of code"



More information about the Python-list mailing list