473,698 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AndAlso & OrElse

I kinda just stumbled across these operators, they seem great, as you can forget the second expression depending on the result of the first, but are there any cons to using these?

From my viewpoint it seems I can pretty much to a find / replace on my existing code and pick up a performance boost, but something seems fishy that I really never see other people using these!

Thanks for any insight!
--Michael
Nov 20 '05
16 1791
"Raterus" <ra*****@spam.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I kinda just stumbled across these operators, they seem great, as you can forget the second expression depending on the result of the first, but are there any cons to

using these?

Only their obscurity, I guess.

Personally, I use them WAY more than the regular versions. Almost
exclusively, in fact. I might even argue that they should be the default
behavior, same as Bob. I do have a number of cases where evaluating both
sides is desirable, but not very many!

I can understand the MS position on backward compatibility, since before
VB.NET there was VB6, and no shortcut operators. I guess that is the
compatibility they were concerned about. The "feature" dates all the way
back to Dartmouth BASIC - doesn't have much to do with MS, since Bill was in
diapers at the time. :-)

I'm not able to think of a single con against their use.

Best Regards,

Andy
Nov 20 '05 #11

"Bob" <no****@nowhere .com> wrote in message
news:Os******** ******@tk2msftn gp13.phx.gbl...
I got into an argument with someone from MS over why they didn't make
short-circuiting logical operators the default so you didn't need the
longer-to-type, rather goofy-sounding AndAlso/OrElse. They said it would
"break existing code". Yet this rings false to me; when they first released DotNet they didn't *have* any existing code. And even if there was any, the only things that would break deserved to break. Or throw an autoreplace
feature in the useless Upgrade Wizard. I can think of no good reason
whatsoever to create code that depends on non-short-circuiting logical
operators. Haven't all languages (aside from pre-NET VB) short-circuited
since the creation of computers?


Many languages have different operators for Boolean operations vs. bitwise
operations, for example C[++/#]'s | and ||, and & and &&. VB did not, until
now. I don't have a problem with the new names.
Nov 20 '05 #12
heh, if you search around you will find some other rants on this subject. The
big thing came down to separating the bit-wise and logical operators. In the
early betas, they implemented the BitAnd, BitOr, etc. to replace the old And,
Or, and instead implement those as true Logical operators as they are most
commonly used. However, in the end they gave in to whining from old school VB
programmers (and newbie's who don't know better yet) who have come to rely on
the oftentimes too flexible and vague stuff VB would let you get away with. So
they removed the explicit bit-wise operators and kept them as And/Or/etc. So
even though you are using them as logical, they are really bit-wise. This still
required the addition of the short-circuit operator AndAlso/OrElse.

Personally, I would have much preferred the separation of the operators, and I
know I'm not alone. However, in the end I think we were in the minority.

Gerald

"Bob" <no****@nowhere .com> wrote in message
news:Os******** ******@tk2msftn gp13.phx.gbl...
I got into an argument with someone from MS over why they didn't make
short-circuiting logical operators the default so you didn't need the
longer-to-type, rather goofy-sounding AndAlso/OrElse. They said it would
"break existing code". Yet this rings false to me; when they first released
DotNet they didn't *have* any existing code. And even if there was any, the
only things that would break deserved to break. Or throw an autoreplace
feature in the useless Upgrade Wizard. I can think of no good reason
whatsoever to create code that depends on non-short-circuiting logical
operators. Haven't all languages (aside from pre-NET VB) short-circuited
since the creation of computers? Now that they set it one way, though, we're
probably going to have to live with this (IMHO) asinine VB "feature"
forever.

Bob

"Jeff Johnson [MVP: VB]" <i.***@enough.s pam> wrote in message
news:uP******** ******@TK2MSFTN GP12.phx.gbl...

"Raterus" <ra*****@spam.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I kinda just stumbled across these operators, they seem great, as you can forget the second expression depending on the result of the first, but are there any cons to using these?


Interesting you shouild mention you just "stumbled across" them, because
they were touted as a new feature of VB.NET. Finally VB got true
short-ciruiting. Perhaps they weren't touted loudly or perhaps you weren't

a
VB6 person and therefore never looked into the "new features" news.

The classic example of the main con to using these operators is when you

do
something stupid like change the state of your application during a test.

In
VB, that would basically mean that your If clause would have to contain a
function call as one of its (second or later) tests and that function call
would "do something," like changing the value of a variable, as opposed to
just testing and returning a result. This is generally considered bad
programming practice anyway, so there is virutally no down side to these
operators.

Nov 20 '05 #13
"Raterus" <ra*****@spam.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I kinda just stumbled across these operators, they seem great, as you can forget the second expression depending on the result of the first, but are there any cons to

using these?

Only their obscurity, I guess.

Personally, I use them WAY more than the regular versions. Almost
exclusively, in fact. I might even argue that they should be the default
behavior, same as Bob. I do have a number of cases where evaluating both
sides is desirable, but not very many!

I can understand the MS position on backward compatibility, since before
VB.NET there was VB6, and no shortcut operators. I guess that is the
compatibility they were concerned about. The "feature" dates all the way
back to Dartmouth BASIC - doesn't have much to do with MS, since Bill was in
diapers at the time. :-)

I'm not able to think of a single con against their use.

Best Regards,

Andy
Nov 20 '05 #14
> I got into an argument with someone from MS over why they didn't make
short-circuiting logical operators the default so you didn't need the
longer-to-type, rather goofy-sounding AndAlso/OrElse. They said it would
"break existing code". Yet this rings false to me; when they first released
DotNet they didn't *have* any existing code.


Try to tell that to all the people porting VB6 code. (Just let me get my flame-proof suit on first.)

--
Jonathan Allen

Nov 20 '05 #15
Bob
If MS had made AndAlso/OrElse the non-short-circuiting logical operators, it
would have been simply a question of auto-replacement either manually or
through the upgrade wizard.

But really, most VB6 projects of any significant complexity are junk simply
because there are so many fundamental things missing in the language. IMHO
it all begs to be rewritten.

Bob

"Jonathan Allen" <Jo***********@ discussions.mic rosoft.com> wrote in message
news:C6******** *************** ***********@mic rosoft.com...
I got into an argument with someone from MS over why they didn't make
short-circuiting logical operators the default so you didn't need the
longer-to-type, rather goofy-sounding AndAlso/OrElse. They said it would
"break existing code". Yet this rings false to me; when they first released DotNet they didn't *have* any existing code.
Try to tell that to all the people porting VB6 code. (Just let me get my

flame-proof suit on first.)
--
Jonathan Allen


Nov 20 '05 #16
I have to admit, I would rather rewrite it by hand than try to use the
upgrade wizard.

--
Jonathan Allen
"Bob" <no****@nowhere .com> wrote in message
news:eC******** ******@TK2MSFTN GP10.phx.gbl...
If MS had made AndAlso/OrElse the non-short-circuiting logical operators, it would have been simply a question of auto-replacement either manually or
through the upgrade wizard.

But really, most VB6 projects of any significant complexity are junk simply because there are so many fundamental things missing in the language. IMHO
it all begs to be rewritten.

Bob

Nov 20 '05 #17

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

Similar topics

10
4629
by: Mike Hale | last post by:
Is it better to use AndAlso and OrElse by default rather than the regual And & Or? MikeH
11
6483
by: A Traveler | last post by:
I was just curious if anyone knows how the combinations of And/AndAlso and Or/OrElse compare in terms of performance. Which takes more work for the system, performing two evaluations on an And or performing short-circuiting on an AndAlso? Purely for enlightenment. Thanks in advance. - Arthur Dent.
9
10381
by: Lior | last post by:
Hello . I know that the AndAlso and OrElse statements are short-circuiting And and Or statements , respectively . Should I always use (I don't like the word "always" ...) AndAlso instead of And and OrElse instead of Or ?
30
4578
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, If x = y And m = n The .... End If If x = y AndAlso m = n Then .... End If
3
19245
by: Siegfried Heintze | last post by:
Are there operators in C# that are the counterparts of "OrElse" and "AndAlso" that I can use when translating the following program from VB.NET to C#? Thanks, Siegfried Namespace vbtest Module Main Function reflect(x as boolean) as boolean
8
1252
by: Euvin | last post by:
I am kind of confuse as to how these operators work: AndAlso and OrElse Anyone care to explain. Some examples would be great!
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
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 we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.