Page MenuHomeFeedback Tracker

a && b Lazy Eval
Closed, ResolvedPublic

Description

Short but sweet,

https://community.bistudio.com/wiki/a_&&_b

What exactly is the purpose of having two different ways of using (a && b), one with and one without lazy eval.

More importantly, what exactly is the point in checking the second condition if the first condition clearly returns as false, the method or function will never execute if one condition is not met so why even waste the resources or slight performance strike to check?

Yes, I know that performance hits aren't big for small tasks, but that doesn't mean absolutely pointless things should exist and be worked around.

Details

Legacy ID
2607292129
Severity
None
Resolution
Open
Reproducibility
Always
Category
Scripting

Event Timeline

ColinM9991 set Category to Scripting.Nov 4 2015, 11:00 PM
ColinM9991 set Reproducibility to Always.
ColinM9991 set Severity to None.
ColinM9991 set Resolution to Open.
ColinM9991 set Legacy ID to 2607292129.May 8 2016, 1:03 PM

It's useful if the value of b is actually the result of a function call that has side-effects. In this situation you may want the function to be evaluated even if the resulting expression is false (because the value of a is false). I do agree that the alternative syntax is not intuitive though.

commy2 added a subscriber: commy2.May 8 2016, 1:03 PM

What exactly is the purpose of having two different ways of using (a && b), one with and one without lazy eval.

The point of having both lazy and eager evaluation is that they are different.

The way the current compiler works, it is not possible to for example

a || b

to stop evaluation if a is true, but

a || {b}

scope with b will be ignored, unless a is false. Ideally it would have benefited to have lazy eval all the time, unfortunately not possible with current compiler.

neokika closed this task as Resolved.Nov 1 2016, 1:13 PM
neokika claimed this task.
neokika added a subscriber: neokika.

While the syntax is not great, it's something we will have to live with.