473,732 Members | 2,043 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 5363
"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
2390
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
3512
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
5072
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
8944
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
8773
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
9306
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...
1
9234
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
9180
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
8186
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4548
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
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.