int/long unification hides bugs
clifford.wells at comcast.net
Tue Oct 26 07:34:42 CEST 2004
On Mon, 2004-10-25 at 21:25 -0700, kartik wrote:
> integers are used in different ways from strings. i may expect file
> paths to be around 100 characters, and if i get a 500-character path,
> i have no problem just because of the length. but if a person's age is
> 500 where i expect it to be less than 100, then **definitely**
> something's wrong.
So Python should raise an exception if it notices that your variable is
named "age" and you've put a number greater than 100 in it? I'm amazed
there isn't already a PEP on this. Have you checked to make sure?
> as another example, using too long a string as an index into a
> dictionary is not a problem (true, the dictionary may not have a
> mapping, but i have the same issue with a short string). but too long
> an index into a list rewards me with an exception.
I'd rather be rewarded with a cookie.
> as i look at my code, i rarely have an issue with string sizes, but if
> an integer variable gets very large (say > 2**31 or 2**63), it
> generally reflects a bug in my code.
Well, of course. After all, there are only 2**63 numbers in the
universe, so any number higher than that is clearly an error. In fact,
given that so many people use numbers on a regular basis, I suspect
there are actually far fewer numbers left now than there were
> i suggest u base your comments on real code, rather than reasoning in
> an abstract manner from your ivory tower.
I can see why you would want to avoid that.
Cliff Wells <clifford.wells at comcast.net>
More information about the Python-list