473,508 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

automatic type conversion for comparison operators

I posted a message on this several days ago, but it apparently got
lost
in googlespace, so I'll try it again.

I recently discovered a bug in my code that apparently resulted from
the automatic conversion of a function pointer to an integer.

Say you have a class member function called getCount(), which
returns an integer. Now suppose you write something like

if obj.getCount < 3: ...

This is an error because the parentheses were left off. But Python
somehow compares the function pointer with an integer without
complaining. Unless there is a darn good reason for allowing
comparisons of this type (and I can't think of one), I think
Python should flag this as an Exception.

Jul 26 '07 #1
3 1240
On Jul 26, 6:22 pm, Russ <uymqlp...@sneakemail.comwrote:
I posted a message on this several days ago, but it apparently got
lost
in googlespace, so I'll try it again.

I recently discovered a bug in my code that apparently resulted from
the automatic conversion of a function pointer to an integer.

Say you have a class member function called getCount(), which
returns an integer. Now suppose you write something like

if obj.getCount < 3: ...

This is an error because the parentheses were left off.
BTW, are you a former Pascal programmer?
But Python
somehow compares the function pointer with an integer without
complaining. Unless there is a darn good reason for allowing
comparisons of this type (and I can't think of one), I think
Python should flag this as an Exception.
IIRC, the reason is for backwards compatibility with a long-obsolete
version of Python in which it wasn't possible for __cmp__ to throw an
exception. That's not darn good, so this behavior is already slated
for removal in version 3.0.

Jul 26 '07 #2

Dan Bishop wrote:
BTW, are you a former Pascal programmer?
No. Why do you ask? [The code snippet I wrote was made up to get a
point across. I
did not actually use that function name in my code.]
But Python
somehow compares the function pointer with an integer without
complaining. Unless there is a darn good reason for allowing
comparisons of this type (and I can't think of one), I think
Python should flag this as an Exception.

IIRC, the reason is for backwards compatibility with a long-obsolete
version of Python in which it wasn't possible for __cmp__ to throw an
exception. That's not darn good, so this behavior is already slated
for removal in version 3.0.
That's good to know. Thanks.

Jul 27 '07 #3
On Jul 26, 8:04 pm, Russ <uymqlp...@sneakemail.comwrote:
Dan Bishop wrote:
BTW, are you a former Pascal programmer?

No. Why do you ask? [The code snippet I wrote was made up to get a
point across. I
did not actually use that function name in my code.]
I just have a hypothesis that former Pascal/Basic programmers are much
more likely than C/C++/Java programmers to forget the () on a function
call. Nothing to do with the (Java-like) function name.

Jul 27 '07 #4

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

Similar topics

21
4493
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
7
1814
by: bartek | last post by:
Please consider the following scenario below (sketch of). There are two templates defined: A and B, both with mutual conversion operators defined. Also, there's a free function template...
8
2221
by: Rade | last post by:
Following a discussion on another thread here... I have tried to understand what is actually standardized in C++ regarding the representing of integers (signed and unsigned) and their conversions....
7
2232
by: Madhu Gopinathan | last post by:
Hi, I hope this is the right forum for this question. I am extending ICollection to create a Collection Type (say MyCollection) wherein I can control the types of objects being added to the...
3
7699
by: PeterK | last post by:
I am trying to set Public overridable CreditlimitS() as System.Data.SqlTypes.SqlMoney to Creditlimit as Double like CreditLimitS=creditlimit and get this error "Value of type double cannot be...
1
11235
by: Philip Bondi | last post by:
Hello to all SQL Server junkies who work with non-English characters: For people running scripts from the command line using ANSI files with special characters, it is very important to use isql...
7
4211
by: Ben R. | last post by:
How does automatic type casting happen in vb.net? I notice that databinder.eval "uses reflectoin" to find out the type it's dealing with. Does vb.net do the same thing behind the scenes when an...
4
1497
by: swansnow | last post by:
This is perhaps a basic question, but it's been a while since I've done C, and none of the searches I did on operators and data types wanted to address this, so here goes... In the glibc (linux)...
2
2290
by: java | last post by:
Hi: There is an introductory diagram for those confused by javascript type wrangling (i.e., runtime type conversion by the javascript interpreter). http://mollypages.org/misc/jstypes.mp ...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.