Should I replace all my if / else statements with a triple shorthand if / else? (Php)

I read about the if / else triple abbreviation, and I wonder if it makes sense or would be more useful to replace all (or most) of my traditional if / else triple abbreviations? Will it work faster? Or will all the benefits be that it is less than code?

Thank you for understanding!

+3
source share
10 answers

Ternary if / then statements should be used for basic logic when there is a clear choice in any case. When you start embedding triple if / then statements, you simply make more headaches for yourself (or your future successors), when changes need to be made or mistakes should be corrected.

As for speed boosts, you won't see the difference between triple or normal statements. However, you will save several bytes from the file size, although this is probably not enough to be remotely obvious.

+7
source

That would be pointless. Ternar is useful only in very "primitive" conditions, and most are ifmore complicated.

You will lose a lot of time in order to gain nothing.

+6
source

, , .

, , .

+3

, / .

, , , .

+1

. , . if-else, , . , $var = $bool ? "IF TRUE" : "IF FALSE". if , .

+1

, , else ifs? ,

0

- ( ). if/else .

if/else ( if), , , , , , , , if, - , , .

0

, ifs , . , , .

, , .

, , ,

0

, .

, .

, .

0

, VS2010,.NET 4.0, 18% 22% , if-then.

0

Source: https://habr.com/ru/post/1781721/


All Articles