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

Home Posts Topics Members FAQ

Lazy evaluation?

Hi again,

I've been coding in vb .Net on my most recent project and during a debug
session I noticed that VB .Net hasn't got lazy evaluation... WHY?! I love
lazy evaluation and actually count on it.

In my current application there is data that may or may not exist depending
on a certain value. It's a set of rules that may or may not apply.

At a certain time in the code, there is the following (alike anyhow) statment.
If ((objectA.HasRu le4 AND objectB.FailsRu le4(params))
OR (objectA.HasRul e5 AND objectB.FailsRu le5(otherparams ))
OR (not objectA.Propert y.Value.equals( objectB.Propert y.Value)) then
collectionOfObj ectB.Remove(obj ectB)
else
objectB.Calcula tespecialfield( )
end if

When I write this code I expect the run to check on objectA.Hasrule 4 if that
is false it should move on to the next or-statement.

Is there any possibility to tell VB .Net (or rather VS 2003) to apply lazy
evaluation for conditional statements?

As usual many thanks in advance, and enjoy your holidays :)
Dec 23 '05 #1
4 5361
"SL33PY" <SL****@discuss ions.microsoft. com> schrieb:
I've been coding in vb .Net on my most recent project and during a debug
session I noticed that VB .Net hasn't got lazy evaluation... WHY?! I love
lazy evaluation and actually count on it.


You may want to use the 'AndAlso' and 'OrElse' operators instead of 'And'
and 'Or'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 23 '05 #2
SL33PY,
As Herfried suggests, use AndAlso & OrElse; As And & Or are binary logical
operators, while AndAlso & OrElse are Short-Circuiting Logical operators.

http://msdn2.microsoft.com/en-us/library/wz3k228a.aspx

http://msdn.microsoft.com/library/de...idxlogical.asp

NOTE: AndAlso & OrElse first appeared in .NET 1.0 (VS 2002).

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"SL33PY" <SL****@discuss ions.microsoft. com> wrote in message
news:16******** *************** ***********@mic rosoft.com...
| Hi again,
|
| I've been coding in vb .Net on my most recent project and during a debug
| session I noticed that VB .Net hasn't got lazy evaluation... WHY?! I love
| lazy evaluation and actually count on it.
|
| In my current application there is data that may or may not exist
depending
| on a certain value. It's a set of rules that may or may not apply.
|
| At a certain time in the code, there is the following (alike anyhow)
statment.
| If ((objectA.HasRu le4 AND objectB.FailsRu le4(params))
| OR (objectA.HasRul e5 AND objectB.FailsRu le5(otherparams ))
| OR (not objectA.Propert y.Value.equals( objectB.Propert y.Value)) then
| collectionOfObj ectB.Remove(obj ectB)
| else
| objectB.Calcula tespecialfield( )
| end if
|
| When I write this code I expect the run to check on objectA.Hasrule 4 if
that
| is false it should move on to the next or-statement.
|
| Is there any possibility to tell VB .Net (or rather VS 2003) to apply lazy
| evaluation for conditional statements?
|
| As usual many thanks in advance, and enjoy your holidays :)
Dec 23 '05 #3
Sl33py,

Is there any possibility to tell VB .Net (or rather VS 2003) to apply lazy
evaluation for conditional statements?

You saw that it is not true, the told reason was that the Or and And should
keep their classic behaviour for backwards compatibility. Something found by
probably most real VB.Net developers not the wise decision afterwards,
especially not if you see how much the VB6->VBNet converters are changing.

However it was done. I hope that backward compatible devil will soon be
forgotten and code will be made in a way that it is as well for not classic
VB users (who know the history) optimal understandable way.

Just my thought,

Cor
Dec 23 '05 #4

SL33PY wrote:
Hi again,

I've been coding in vb .Net on my most recent project and during a debug
session I noticed that VB .Net hasn't got lazy evaluation... WHY?! I love
lazy evaluation and actually count on it.


This isn't really what usually gets the name 'lazy evaluation', btw;
this is usually called 'short-circuited conditionals'. Others have
given you what you need.

--
Larry Lard
Replies to group please

Dec 23 '05 #5

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

Similar topics

25
2385
by: Steven Bethard | last post by:
So I end up writing code like this a fair bit: map = {} for key, value in sequence: map.setdefault(key, ).append(value) This code basically constructs a one-to-many mapping -- each value that a key occurs with is stored in the list for that key. This code's fine, and seems pretty simple, but thanks to generator
9
3508
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by allowing the assignment operator (=) to be overloaded. One particular use for this would be to implement "lazy evaluation". For example it would allow us to get rid of all the temporary arrays produced by NumPy. For example, consider the...
39
5063
by: Boltar | last post by:
Why does C do lazy evaluation for logical boolean operations but not bitwise ones? Ie: the following program prints "1 2" , not "1 1" under gcc main() { int a = 1; int b = 1; 0 && ++a;
0
8608
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8867
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
4370
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
3050
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
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.