- 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
Coercive frist
inb4 TRWTF is Ruby
Admin
So it's used in TimestampHelper.
Filed under: That's certainly true, but don't call me Turley
Admin
Dammit @Remy, you beat me to the "nothing is true, everything is permitted" joke. I would've added some hilarious Assassin's Creed reference, but it's too late now thanks to you.
Then again, the pointless war joke was way better than anything I would have come up with. That's why you're the writer and I'm not.
Admin
Just to be clear, everything except for
false
andnil
is truthy (but nottrue
) in Ruby. Comparison is very strict: the expressionsfalse==nil
,0=="0"
and1==true
all evaluate tofalse
.Without context it is hard to say whether the original function is indeed a WTF. It certainly looks like one. But sometimes you need to read data from different sources and you may get a
1
from the C module, a"1"
from the XML, ortrue
from your serialized dump. Though actually having the length check after accessing the first element would require a very WTF context to be justifiable. So I give this function the :wtf: of doubt.Admin
That coworker forgot the case when both parameters are arrays.
And, it woudl be faster to compare the array length to 1 before evaluating the string representation of the element #0. (Unless an array is stored as a continuous byte array where each element is preceded by its length, or as a delimiter-delimited string.)
And, using ternary operators would be more elegant, you could omit the return keyword altogether for example.
Admin
The main problem here is putting both the "extract actual truth value of variable" and comparison in the same function.
Should have implemented a function that does the actual conversion/parsing etc. to a boolean value, a function guaranteed to return True or False, and then make a basic comparison on the returned values.
Admin
https://twitter.com/chris__martin/status/630532950484881412
Admin
I'm of the opinion that in order to sustain an adequate level of maintainability, it can be a good idea to impose coding standards that require the developer to use a strictly limited set of variables which can be interpreted as booleans. For example, when using java, only the boolean true/false and (as appropriate) True/False are to be used. When using c, only 0 and 1 (oh all right, a non-zero integer) are to be used. And when using Ruby, only false and true are to be used. A nightmare to impose -- you need a rigorously enforced programming review phase. And I mean rigorous.
I have the delightful privilege of maintaining a system written using what is most politely described as a "proprietary business-friendly language" (i.e. a C21 COBOL) in which there are the following lists declared:
That's what happens when you let business analysts loose on software design.
Admin
Gah!
That is one bad pile of #¤&/¤#.........
I pity the one who have to compare between any of those 'styles'.....
Admin
Admin
So.... equivalent_values(true, true) gives false....?
Admin
Lisa worked on Discourse?
Admin
Just thought I should come up with a function to test the long-term truthiness of a process. If it is called more often with true than false; then it is "truthy."
Admin
I... That... That's horrible. Why would you ever do that? AAAAAAAAAAAUUUUUUUUUUUUUUGGGGGHHHHHHHHH
Admin
Because some
idiot made up the words "truthy" and "truthiness" for an article?idiotoverly clever authorI mean seriously, think of the statements...
"This program is kind of truthy." "How is it we test for truthiness again?" "It just sorta-kinda looks truthy over there."
Admin
Yeah. You should definitely use
BigInteger
instead oflong
.Admin
The truth??
You can't handle the truth!!
Look, somebody had to do it.
Admin
Will the new forum have a dislike button?