|
-
Sep 10th, 2003, 10:09 AM
#1
Thread Starter
Frenzied Member
.NET cluture shock: #1 Short curcuit evaluation
In visual basic 6 (and all previous versions) every component of a logical expression was executed.
For example if you have:
VB Code:
If chk1.Value = vbChecked Or chk2.Value = vbChecked Then
Then even though the second part of the expression can have no effect if the first part is true it is always tested anyway (which is an unneccessary overhead).
VB.Net introduces two new keywords, OrElse and AndAlso. These perform a lazy evaluation i.e. if the left hand side gives you sufficient information to calculate the logical operator then the right hand side is not evaluated. The keywords or and and still operate as they did but now we have the choice of whether or not to optimise our logical operations.
-
Sep 10th, 2003, 10:54 AM
#2
Thats bizzare, I thought it did that as standard (like Java), as I am defintly sure Ive seen it happen in my code without specifying the keywords myself.
Didnt know the keywords though.
On another point, theres a nice function called DirectCast which I didnt know about (use instead of Ctype).
-
Sep 10th, 2003, 12:18 PM
#3
Originally posted by Grimfort
Thats bizzare, I thought it did that as standard (like Java), as I am defintly sure Ive seen it happen in my code without specifying the keywords myself.
Didnt know the keywords though.
On another point, theres a nice function called DirectCast which I didnt know about (use instead of Ctype).
I think they did it so it would work by default in the beta versions... the had some other keywords for the current AND and OR I believe...
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Sep 10th, 2003, 04:51 PM
#4
Nah, it was a couple of weeks ago, in full VS.Net 2002.
I noticed it cos I program in other languages and was suprised that it worked.
I tested it earlier on, and it didnt work I love programming.
-
Oct 28th, 2004, 08:37 AM
#5
Hyperactive Member
Just curious
Now that we have "short-circuiting" operators (AndAlso & OrElse)
Is there ever a time when we'd want to use just plain And or Or?
I like the sound of "OrElse", I'm going to use that as often as possible in my code!
Has anyone seen the new "Open-circuiting" operator called False?
It works like this:
Code:
If False Then
' All code here is skipped to save time
' This can make your code hyper fast!
End If
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Oct 28th, 2004, 08:56 AM
#6
You typically use long winded evaluation when you are using functions that do work as well as returning a value e.g.:
VB Code:
If DeleteUser("djones") AND PurgeLogs("djones") Then
Trace.WriteLine("User cleared out", Me.GetType.ToString)
End If
If there was an AndAlso there then the logs wouldn't get purged.
-
Oct 28th, 2004, 07:30 PM
#7
umm correct me if I'm wrong, but I think C++ syntax language doesnt have the VB type AND and OR, they just have vb's AndAlso and OrElse....
since it's like this I would say it's better to just stick with AndAlso and OrElse, just to get used to C++ style programming which seems a little better . Dont use AND or OR
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|