473,473 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Comparisions

This is not really a problem, but I am curious to know why.

Is this just a programming style, or are there any performance /
compilation gains from writting comparsion differently;

if ( null == TimeOfDay )

if ( TimeOfDay == null )

I've been seeing a lot a mixed code simular to this and I just want to
know if there is a particular reason for it.

Thanks for any insights

Nov 17 '05 #1
1 928
In older languages like C and C++ conditionals like if statements did not
just operate on booleans.... for example you could do something like if(45).
This meant that if you mistyped == as = you'd end up with something like:

if(myString = null)

instead of:

if(myString == null)

now in C and C++ the mistyped one, if(myString = null) will ALWAYS evaluate
to true because the assignment of null to myString is successful so you have
now changed myString to null instead of doing a simple test to see if it was
null.

To get around this people used to put null first. This is because null is
fixed and so cannot be changed. If you typed:

if(null = myString) instead of if(null == myString) the compiler would give
an error as you can't assign anything to null... null is null and that's that.

Newer languages like C# don't have this problem because conditionals only
work on boolean expressions and assignment isn't a boolean expression. If you
see it in code it's a good indication that the person who wrote it comes from
a C/C++ background.

Hope this answers your question

Brian Delahunty
Ireland

http://briandela.com/blog
"qu*******@resolutionsnet.co.uk" wrote:
This is not really a problem, but I am curious to know why.

Is this just a programming style, or are there any performance /
compilation gains from writting comparsion differently;

if ( null == TimeOfDay )

if ( TimeOfDay == null )

I've been seeing a lot a mixed code simular to this and I just want to
know if there is a particular reason for it.

Thanks for any insights


Nov 17 '05 #2

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

Similar topics

12
by: Deke | last post by:
I will be embarking on a large web project. I am still researching as to which language use - PHP or Perl. Can someone clear up some of the bad publicity with PHP in the links below? They are...
4
by: danaf | last post by:
Dear all, (1)Is it possible to host PHP-based Web Portal + MySQL Database (e.g. PHPNuke) on MS Windows System? If yes which server software I need? (2)Compare PHP over JSP/ASP/CGI in...
6
by: Vince | last post by:
Hi, I am working on a project involving contactless card and to read or write into these cards we need some parameters (Key to use for instance). My problem is to store these parameters in the...
45
by: Alex | last post by:
I know this is a religious issue, and I hope this thread doesn't degenerate, but I am curious about the pros and cons of swapping the operands of ==. The only pro of putting the constant on the...
65
by: He Shiming | last post by:
Hi, I just wrote a function that has over 200 "cases" wrapped in a "switch" statement. I'm wondering if there are performance issues in such implementation. Do I need to optimize it some way? ...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
16
by: Cybex | last post by:
Can you have one or the other type conditions for a do while loop? See the non-working code below... do { cout << "Are you a Member or Non-member? Enter 'M' or 'N': "; cin >charMstat;...
1
by: pitjpz | last post by:
We have moved our Database to another server. The server it was on used SQL 4 and the new one its on now uses SQL5 the only problem we can find is that when you attempt to delete a record from...
4
by: Prashanth Kumar B R | last post by:
Hi, I have situation in C++ where in I'll have to add around 20-25 conditions <compare a variable against a number> to an if statement. Is there any limit on the number of expressions/conditions...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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.