Representative Line: Tern on the Flames
There's nothing inherently wrong with the ternary operator. It's just the kind of thing that gets abused.
Now, we all know how it should be used. We frequently would write something like this:
let val = arr.length>0?arr[0].id:0;
If the array contains elements, grab the first one, otherwise use a reasonable default. It's not my favorite convention, but it's fine. Nothing worth complaining about.
Lahar Shah's co-worker has a different approach to this.
// Set value for tempVariablearr.length > 0 ? tempVariable = arr[0].id : tempVariable = null;
It's amazing how converting a ternary from an expression which evaluates to a value into a statement which changes program state makes it feel so much grosser. There's nothing technically wrong with this, but it makes me want to set the code on fire and dance naked around the flames.
This, of course, wasn't a one-off use of the ternary operator. This was how the developer used the ternary, forever and always.
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!