- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Bet it was an inTERN who wrote this TERRNible code.
Admin
if Captain Jack Sparrow is the best pirate I have ever seen, then Will Terner will be the best TERNer I have ever seen
Admin
Did you find this on the inTERNet?
Admin
Seeing a bad trend recently – Remy starts every article talking about himself.
Admin
At least there was an alTERNative.
Admin
Sadly, the replacement function doesn't account for the fact that JS has falsy values that are neither
null
norundefined
, and the behaviour is changed for those values.Admin
Tern away from javascript, lest ye lose all hope,
Admin
Another WTF was missed, the poor method name which breaks encapsulation.
The method name in my mind implies that it is a "command" that will disable the "estimateSent" when called, but in actual fact it's "query" whose return value lets you know whether or not estimateSent should be enabled.
I would rather name it something like one of the following:
enabled="{{ !estimateSent }}"
in my view.)Admin
bad ternd
Admin
Not, unless I'm missing something, if that object is a boolean.
Admin
If the value is the integer 0, the old function returns !true ==> false, but the new function returns !(falsy==>false) ==> true.
And of course I wrote my initial comment wrong. It should have been "neither false nor undefined". null is falsy, but its return, too, would change from false in the old to true in the new because it isn't false and it isn't undefined. (Unlessly unless I missed something about
null == false
and/ornull == undefined
Oh, bugger. It's JS, so that
==
is going to do reckessly heroic (heroically reckless?) levels of conversion. Ugh. Never mind.Admin
Wtf? The biggest wtf is mixing 4 different seemingly unrelated concepts: "estimate," "survey," disable/enable, send/receive
Admin
return !modalControl.survey[0].Survey_Complete
That's danged elegant - especially when compared to the monstrosity it replaced. Calling it "prosaic" minimizes the value of clean code.
Admin
The new function is not equivalent to the old one. It should be
!(modalControl.survey[0].Survey_Complete == false)
in order to work the same way. The original only returns true if the variable is false (not falsy), if I'm not mistaken.Admin
Welp, I misread the code, so nevermind. Steve's point still stands.
Admin
falsy? Surely falsey? aaiiii!!! falsies!
Admin
I'm throwing my un-ternarying change before the judges (for me it was a huge improvement in read-/understandability):
Before: return labelKey == null ? null : varyingToolTipText ? messageSource.getMessage(new DefaultMessageSourceResolvable(new String[] {labelKey + TOOLTIP_SUFFIX, labelKey})) : shortNameInList ? messageSource.getMessage(labelKey) : null;
After: if (toolTipMessageKey != null) { return messageSource.getFormattedMessage(toolTipMessageKey, toolTipArguments); }
Admin
Is this a "it's all in the formatting" thing? (I see the BB has helpfully munted some of your formatting -- we'll see how my reply fares.) If you formatted it like the below, would that be equally clear?
Admin
It is not a bad idea to avoid refraining from not using multiple negating cascades.
Admin
Admin
Remy, your code should be:
const ControllerState response = allMotorsIdle() ? READY : NOT_READY;
The ability to initialize a constant with the const keyword is IMHO a much overlooked advantage of the ternary operator.
Admin
Meh. This is not even the worst code that I have seen today.
Admin
That's not even bad. Clearly the ternary is wrong but by the time you've seen the "return !" you can mentally switch true/false in the prevkious line and, because a ternary returns a boolean, it immediately cancels itself out and the whole function collapses into a simple "double test". If I was refactoring I'd make that change then and there before even thinking about what the function did. If I was just reading code I'd make a mental note and just carry on.
I give this one 4 out of 10.