int/long unification hides bugs
Josiah Carlson
jcarlson at uci.edu
Tue Oct 26 01:57:18 EDT 2004
kartick_vaddadi at yahoo.com (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 *you* need to do bounds checking. Last time I checked, Python didn't
raise an overflow error on getting to 500, so you're going to need to do
the check anyways.
> 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.
And you should check that, and not rely on a misfeature and a mistake.
It is going in whether you like it or not, and has been planned since
Python 2.3.
> i suggest u base your comments on real code, rather than reasoning in
> an abstract manner from your ivory tower.
Ahh, real code. Ok *rummages through some code*. Yeah, so I checked,
and I don't rely on overflow errors. I use explicit bounds checking in
all cases where values outside my expected range can come. Then again,
I prefer to check my variables when I rely on them.
- Josiah
More information about the Python-list
mailing list