473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.HasRule4 AND objectB.FailsRule4(params))
OR (objectA.HasRule5 AND objectB.FailsRule5(otherparams))
OR (not objectA.Property.Value.equals(objectB.Property.Val ue)) then
collectionOfObjectB.Remove(objectB)
else
objectB.Calculatespecialfield()
end if

When I write this code I expect the run to check on objectA.Hasrule4 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 5328
"SL33PY" <SL****@discussions.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****@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.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.HasRule4 AND objectB.FailsRule4(params))
| OR (objectA.HasRule5 AND objectB.FailsRule5(otherparams))
| OR (not objectA.Property.Value.equals(objectB.Property.Val ue)) then
| collectionOfObjectB.Remove(objectB)
| else
| objectB.Calculatespecialfield()
| end if
|
| When I write this code I expect the run to check on objectA.Hasrule4 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
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...
9
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...
39
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.