News for hackers. Stuff that matters.
Re:Guidelines for writing readable code by esdkl22 on Friday September 14, 2018 @11:22AM (#17987842)
I have a question about point #12. Are most people in agreement that the if else loop is preferrable over a ternary operator?

One of my worst professional programming experiences was having a senior developer who took apart usage of map, filter, reduce, and replaced them with if else loops, and sometimes breaking things in the process.

The idea that you would one day have a junior who would fail to understand a relatively simple concept seems like fantasy. Let them get stumped once, and then teach!

Re:Guidelines for writing readable code by PunchTornado on Friday September 14, 2018 @11:27AM (#17987901)
no, but it all comes to the complexity of the operation.

Like the article said, something like this is better than an if else loop: $variable == $x ? $y : $z;

But if you write stuff like this:

$variable == $x ? ($x == $y ? array_merge($x, $y, $z) : $x) : $y;

I am going to be annoyed. In the second case, please use if else.

Re:Guidelines for writing readable code by esdkl22 on Friday September 14, 2018 @11:29AM (#17987920)
You're correct. I didn't look closely enough at the finalized piece of code. I misinterpreted and thought the offer was unsatisfied with the original, appropriate use for a ternary operator ($variable == $x ? $y : $z)