0

Years ago, I have been told that tests should be built as a funnel : complexity has to grow from left to right (to improve performance I think).

For instance, if ($a == '1') would be better if written if ('1' == $a), because $a complexity is unknown while '1' is low.

Now I don't remember exactly why this rule exists and can't find anything about it since I can't really express it, apart from this page which is a bit shady.

Is this a real thing ? And if so, why ? Please and thank you :)

AlexiZ
  • 1
  • 1
  • 1
    What you're presenting has nothing to do with complexity. Your example and the discussion on that page are referring to [Yoda style](https://en.wikipedia.org/wiki/Yoda_conditions). – El_Vanja Dec 14 '20 at 14:58
  • Well for 1 thing if you used the assignment operator rather than comparison you'd get an error, rather than reassigning. e.g. `if ($a = '1')` vs. `if ('1' = $a )` – user3783243 Dec 14 '20 at 14:58
  • @El_Vanja that's what I was looking for, Yoda Style. – AlexiZ Dec 14 '20 at 15:01
  • @El_Vanja thank you :) – AlexiZ Dec 14 '20 at 15:13

0 Answers0