- 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
What no cornify? No comments except an easy reader version? Who are you and what have you done to the real Remy?
Admin
I've found the WTF: The author of that code forgot to remove emtpy arrays which are true-y when used as a condition of an if-condition (if I understand the handling of empty arrays correctly)!
And why didn't the fathers of JavaScript define undefined right away as false? Would make life so much easier!
Admin
The new 'improved' discussion system - that's the RWTF
Admin
TRWF is of course JavaScript. Not just because it has such f***ed up definitions of truthishness and falsishness, but also in this case because it's too easy to write code that nobody else can understand. And that, above all else, is what kills software development projects.
Admin
It's a CodeSOD, what did you expect?
Admin
Re "And why didn't the fathers of JavaScript define undefined right away as false? Would make life so much easier!"
NetScape released the language to the public too soon while it was really in a prototype or beta stage but the language became very popular right away and hence it was adopted by the public in it's chaotic form before it's design was maturely completed.
Admin
I wondered how long it would take the ravenous hordes to run on the new commenting/forum software they did on Discourse. Well, at least since it's in-house this time, "we" have no one to blame but ourselves.
Admin
So the code itself makes sense, quite frankly. It does what it says it's going to do in a way that's a bit inelegant but quite accurate. The WTF would be the calling code that scrubs falsey values when it expects false values to exist.
Admin
If one wants to install it via npm, then better hurry before the author rage-quits and takes all the delicious wtf's away.
Admin
I agree. It does what the name says and I wouldn't even call it inelegant.
TRWTF is the need for an insane functionality like this in the first place and of course JavaScript for false-y values.
Admin
One could object that JS mature form IS chaotic.
Admin
I think that's what's called a whoosh.
null isn't so bad after all, and using a boolean instead of null is a big WTF no matter whether null is an abomination or not.
Admin
Well at least the downstream doesn't have to check for null and falsey values, right? RIGHT?!??!???
Admin
It seems to me that the author got confused about what he was trying to accomplish. My guess is what was actually intended (or needed, at least) was for the function to force falsey values to canonical false.
Addendum 2016-03-30 12:43: So, using filter was a mistake - he needed to alter the values (through a general map () application) rather than remove them.
Admin
When I needed to recursively modify an object's properties, I used traverse (https://www.npmjs.com/package/traverse). Much easier than that underscore code.
Admin
People might have seen the story recently about the family named null that constantly has trouble with banking, flights, government, etc. How could that happen? "Null" is a string, not the value null, right? Well, now we know exactly how.
Admin
After that story was categorized it's filenotfound-y.
Admin
Real WTF is using blablascript.
Admin
This would have been better if it was rewritten in vanilla Javascript and omitted Underscore, which I wasn't familiar with, instead of trying to explain what Underscore was doing at every step.
Admin
Won't this run forever if it's passed, say, a circularly-linked list?
Admin
It's hilarious that no one, including the author of this article, has spotted the real WTF, which is the fact that the recursive call doesn't work. Sure, it does recurse but the result is discarded and the original value is always returned from filter().