473,789 Members | 2,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

int/long unification hides bugs

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. 2**31 is good
enough for most uses of variables, and when more is needed, 2**63
should do most of the time.

granted, unification allows code to work for larger numbers than
foreseen (as PEP 237 states) but i feel the potential for more
undetected bugs outweighs this benefit.

the other benefit of the unification - portability - can be achieved
by defining int32 & int64 types (or by defining all integers to be
32-bit (or 64-bit))

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.

-kartik
Jul 18 '05
83 3475
kartik wrote:
i suggest u base your comments on real code, rather than reasoning in
an abstract manner from your ivory tower.


Could someone please help me with a related question? Why do I have the
unmistakable feeling that this is a troll? Is it the misspellings? The
gratuitous sniping? Or the OP's suggestions to provide "real code" when
he has not done the same?
--
Michael Hoffman
Jul 18 '05 #31
Michael Hoffman <m.************ *************** ******@example. com> wrote:
kartik wrote:
i suggest u base your comments on real code, rather than reasoning in
an abstract manner from your ivory tower.


Could someone please help me with a related question? Why do I have the
unmistakable feeling that this is a troll? Is it the misspellings? The
gratuitous sniping? Or the OP's suggestions to provide "real code" when
he has not done the same?


It's probably just the usual way he interacts, no big deal. He didn't
ask for real code to be provided, but used to base one's comments on,
please note; and I gave two real-life examples (a woodworking equipment
company in Italy bidding to supply some equipment to a Turkish customer
who prefers to get billed in their local currency; a factorial) without
any trouble and without needing to post the code (it's quite obvious).
Alex
Jul 18 '05 #32
Michael Hoffman wrote:
Could someone please help me with a related question? Why do I have the
unmistakable feeling that this is a troll? Is it the misspellings? The
gratuitous sniping? Or the OP's suggestions to provide "real code" when
he has not done the same?


If you check the archives you'll see the OP's nym come up in two
other hits. One for a proposal to gcc and another as a proposal to
OpenOffice. Both of the sort "I think XYZ would be cool", both using
the poor syntax.

Neither show much troll-like behavior.

My guess is the not unusual case of someone who works mostly alone
and doesn't have much experience in diverse projects nor working
with more experience people.

I've seen some similar symptoms working with, for example,
undergraduate students who are hotshot programmers ... when
compared to other students in their non-CS department but not
when compared to, say, a CS student, much less a experienced
developer.

Andrew
da***@dalkescie ntific.com
Jul 18 '05 #33
Me:
I've seen some similar symptoms ...


But of course correlation does not imply causation and I use
that solely as an example to show how it could be caused by
non-troll behavior.

There could also be cultural reasons, and/or personal ones,
and/or the keyboard could have a broken shift state... Though
that would require '*' to not be on a shifted position.

Andrew
da***@dalkescie ntific.com
Jul 18 '05 #34
Andrew Dalke wrote:
Neither show much troll-like behavior.

My guess is the not unusual case of someone who works mostly alone
and doesn't have much experience in diverse projects nor working
with more experience people.


Perhaps. Maybe I have just been spending too much time in troll-infested
forums, which sets one's troll-o-meter off a lot earlier.
--
Michael Hoffman
Jul 18 '05 #35
On Tue, 2004-10-26 at 09:17 +0200, Alex Martelli wrote:
Cliff Wells <cl************ @comcast.net> wrote:
...
The pivotal word here is "you". The data *you* want to store. One more
time YOU. I'm not correcting your mangling of English at this point,
rather I'm pointing out that it's *you*, not Python, that knows what
sort of data *you* want to store. If *you* want to limit your integers
to some arbitrary amount then *you* are going to have to write code to
do that. What *you* need for *your* application isn't necessarily what
anyone else needs for theirs.
This is correct, but optional constraint checking (on all kinds of data
types) can be a handy feature for many kinds of applications. It might
be handy to have a 'type decorator' for that, one which would wrap all
operations returning a result (and all mutations, for mutables) into
suitable checks. If I have a list that's supposed to always be between
5 and 8 items, it might be handy to write:


<snip speculative examples>
Of course, this has nothing to do with silly and arbitrary bounds such
as 2**31-1. But constraint checking should not necessarily be ruled out
as a generally helpful technique.


Not at all. I do quite a bit of database programming and use
constraints (foreign keys, unique indices, etc) extensively. The
concept is also in widespread use in GUI programming libraries for
controls that deal with user input (e.g. masked input controls). In
fact, most controls present in a GUI implicitly constrain user input
(menus, buttons, etc).

Of course what you describe above can be done now using functions and
derived classes, but it would certainly be interesting to have a general
(and concise) way of describing constraints within the language itself.
Regards,
Cliff

--
Cliff Wells <cl************ @comcast.net>

Jul 18 '05 #36
Cliff Wells <cl************ @comcast.net> wrote in message news:<ma******* *************** *************** *@python.org>.. .
On Mon, 2004-10-25 at 21:48 -0500, Jeff Epler wrote:
Here's a bug that passes silently because ints are not limited in range
from 1 to 100:
...

OK, just joking. I couldn't think of one.


Here's one:

# count how many ferrets I have
ferrets = 0
while 1:
try:
ferrets += 1
except:
break
print ferrets

As you can clearly see, the answer should have been 3, but due to Python
silently allowing numbers larger than 3 the program gets stuck in an
apparently interminable loop, requiring me to reboot Microsoft Bob.


There always were legends that sys.maxferretpo pulation is
implementation-dependant, not readable, and not writable. More
recently the whisper is that at least under Windows it is set by the
installer at installation time using an algorithm known only to the
timbot.
Jul 18 '05 #37
Cliff Wells <cl************ @comcast.net> wrote:
...
Of course, this has nothing to do with silly and arbitrary bounds such
as 2**31-1. But constraint checking should not necessarily be ruled out
as a generally helpful technique.
Not at all. I do quite a bit of database programming and use
constraints (foreign keys, unique indices, etc) extensively. The


Yep, and besides such 'structural' constraints even the simple kind of
check such as "this number is alway between X and Y" may to a lesser
extent come in handy.
concept is also in widespread use in GUI programming libraries for
controls that deal with user input (e.g. masked input controls). In
fact, most controls present in a GUI implicitly constrain user input
(menus, buttons, etc).
A different case, IMHO. An input/'edit' box with inherent checks is a
bit closer.
Of course what you describe above can be done now using functions and
derived classes, but it would certainly be interesting to have a general
(and concise) way of describing constraints within the language itself.


Functions are in general the proper way to check, but having to
explicitly call the checking function each time a change may have
occurred gets old fast.

What I was musing about is (well, half of it) is easy to implement if
you're using qualified names rather than barenames -- each assignment to
a.x may easily be made to go through a setter-function that calls an
appropriate checker function. Attaching similar setter-functions to
barenames is a very alien concept to Python today, but in a sense the
difference could be seen as mere syntax sugar.

The other half of the problem has to do with mutables, and ensuring a
checker function (on object invariants, if you will) runs after each
mutation -- not all that new a notion, just a part of design by contract
(people always focus on preconditions and postconditions and appear to
forget invariants, which are just as crucial;-).

I'm not sure there's a "grand unification" between these halves just
waiting to happen. Surely, though, a little add-on package making it
easy to add checker functions and providing a few typical such checkers
might be of some help. If the checkers could be easily disabled at the
flip of a switch (say the debug flag;-) they might even help by being
potentially-executable specifications of programmer intention (much like
DbC helps in part exactly because it _can_ be disabled that way;-).

Guess I'm mostly musing on the general issue and the 2**31-1 silliness
was just a spark that lit some waiting tinder in my mind;-).
Alex
Jul 18 '05 #38
Cliff Wells wrote:
On Tue, 2004-10-26 at 05:10 +0000, Sam Holden wrote:
On 25 Oct 2004 21:25:07 -0700, kartik <ka************ *@yahoo.com> 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.


What if Noah is using your program?


Then Python clearly needs a special mode so that when a person's age is
entered large numbers are allowed, but when counting animals it throws
an exception if the number is greater than two.

Duh.


And what about Methuselah? He's not going to be receiving his
social security cheques if he can't enter his age as higher than,
say, 2**7 (as our friend kartik would arbitrarily say...). We
actually need 2**10 for his age, but now that's a little too
high so maybe we'd better just kill the old bugger off at 2**9
(hey, he's lived so long that shaving 208 years off his age
won't bother him, right?).

-Peter
Jul 18 '05 #39
On Tue, 2004-10-26 at 09:36 -0400, Peter Hansen wrote:
Cliff Wells wrote: And what about Methuselah? He's not going to be receiving his
social security cheques if he can't enter his age as higher than,
say, 2**7 (as our friend kartik would arbitrarily say...). We
actually need 2**10 for his age, but now that's a little too
high so maybe we'd better just kill the old bugger off at 2**9
(hey, he's lived so long that shaving 208 years off his age
won't bother him, right?).


Ah, the infamous Methuselah quandary. I think actually killing him with
a program would involve specialized hardware (and possibly a gun
permit), which is why this problem has yet to be solved satisfactorily.
Without corporate interest this problem will probably remain unresolved.

Of course the Social Security Administration is one of those places
where constraints define reality, so my guess is he's already received a
letter informing him he's dead and so is no longer eligible anyway. Yet
another example of practicality-beats-purity.

Regards,
Cliff

--
Cliff Wells <cl************ @comcast.net>

Jul 18 '05 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.