Giter Club home page Giter Club logo

Comments (16)

Hywan avatar Hywan commented on August 25, 2024

So, we need a special treatement when dealing with logical operators. Agree?

from ruler.

Hywan avatar Hywan commented on August 25, 2024

Is it considered as a bug?

from ruler.

vonglasow avatar vonglasow commented on August 25, 2024

The common way when we use the "and" operator as php does is to not evaluate the seconds condition. By allow it, we need to change our code regarding what we should do with PHP.

Example:

if (isset($value) && checkSomething($value)) ? echo 'true' : echo 'false';

In this example, until $value is false checkSomething() will never be interpreted!

For someone this could be considered as a bug or an improvement.

from ruler.

Hywan avatar Hywan commented on August 25, 2024

Who want to address this issue? /cc @hoaproject/hoackers

Design and algorithm

We are speaking about introducing lazy evaluation in operators.
Reminder: functions and operators are strictly the same. An operator is just a function with 2 arguments.

The algorithm is the following:

  • we evaluate arguments one after the other,
  • if one is evaluated as X then we Y the evaluation,

where X can be anything and Y can be break or continue.

How to solve?

This can be done in 2 steps:

  1. inside Hoa\Ruler\Model\Operator, we can add a lazy evaluation flag (on or off) and a lazy evaluation condition (X and Y); flag would be turned off by default, on if the operator is and or or,
  2. inside Hoa\Ruler\Visitor\Asserter, in the visitOperator method, the received $element is of kind Hoa\Ruler\Model\Operator, so regarding the lazy evaluation flag and condition, we can visit arguments and apply the above algorithm.

Thoughts?

from ruler.

stephpy avatar stephpy commented on August 25, 2024

This is a good improvement indeed.

from ruler.

jubianchi avatar jubianchi commented on August 25, 2024

👍 I think this is a good improvement... To me, this is not really a bug just a missing feature.

BTW, reading your comments, it seems you only talk about the and operator but this should also apply to the logical or: http://3v4l.org/FPMFp

-- EDIT --

My bad, I just saw the or mentioned in @Hywan's last comment:

flag would be turned off by default, on if the operator is and or or,

from ruler.

vonglasow avatar vonglasow commented on August 25, 2024

@jubianchi 👍
@Hywan 👍

from ruler.

shouze avatar shouze commented on August 25, 2024

@Hywan 👍 and yes should not be tagged as a bug, it's a design consideration (not even sur if it's a feature, should be benchmarked agains more or less complex expressions and if the lazy version wins all time this is not even an option that you can switch on or off).

from ruler.

Hywan avatar Hywan commented on August 25, 2024

Any volunteers for a PR :-)?

from ruler.

vonglasow avatar vonglasow commented on August 25, 2024

Let's go, I will try it!

from ruler.

Hywan avatar Hywan commented on August 25, 2024

@vonglasow w00t! Excellent initiative 👍.

from ruler.

simkimsia avatar simkimsia commented on August 25, 2024

technically speaking, i think this is called boolean short circuit evaluation. Here is a stackoverflow question on this topic http://stackoverflow.com/q/1232603/80353 I think this will be a good feature especially for use cases with 1000s of rules that require assertions.

I think the lazy evaluation or short circuit evaluation should be turned on by default just like most modern languages.

from ruler.

Hywan avatar Hywan commented on August 25, 2024

@simkimsia It will be enabled by default ;-). Thanks for the link!

from ruler.

shouze avatar shouze commented on August 25, 2024

👍 Woot Woot!

from ruler.

vonglasow avatar vonglasow commented on August 25, 2024

I think is done ;)

from ruler.

Hywan avatar Hywan commented on August 25, 2024

@vonglasow Thanks for the clean up ;-).

from ruler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.