473,566 Members | 2,908 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 #1
16 1781
Raterus,

No consequences at all.

Only it looks so strange that most people forget it.

Cor

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!
Nov 20 '05 #2
My two cents - I think they are great operators and I use them all the time.
Like yourself, I stumbled upon them, and was a little cautious at first. I
believe people don't use them because they don't really know they exist.
"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?

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 #3
The con is if the logic in your IF statement depends on all the conditions
being tested.

-Carl
"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?

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 #4

"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 #5
> Jeff Johnson [MVP: VB]wrote:
"]"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.[/quote:f21cad243 1]

They were loudly touted when the operators were still "And" and "Or".
When many old-school VB programmers protested that their 'side-effect'
style of coding would be circumvented, so Microsoft relented and kept
"And" and "Or" behaving as in VB6, i.e., no short-circuiting. Then
the modern programmers protested that they wanted the short
circuiting, so Microsoft relented and added back short circuiting,
but as "AndAlso" and "OrElse" to try to keep everyone happy. (a
classic case illustrating why VB is like it is today).

Nov 20 '05 #6
Bob
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 #7
Bob
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 #8

"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 #9
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 #10

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

Similar topics

10
4622
by: Mike Hale | last post by:
Is it better to use AndAlso and OrElse by default rather than the regual And & Or? MikeH
11
6472
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
10371
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
4552
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
19228
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
1248
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
7666
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...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
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. ...
1
7644
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...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
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
1
1201
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.