• (disco)

    Coercive frist

    inb4 TRWTF is Ruby

  • (disco)

    So it's used in TimestampHelper.

    equivalent_values("2015-29-04",true) == true
    

    Filed under: That's certainly true, but don't call me Turley

  • (disco)

    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.

  • (disco)

    Just to be clear, everything except for false and nil is truthy (but not true) in Ruby. Comparison is very strict: the expressions false==nil, 0=="0" and 1==true all evaluate to false.

    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, or true 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.

  • (disco)

    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.

  • (disco)

    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.

  • (disco)

    https://twitter.com/chris__martin/status/630532950484881412

  • (disco)

    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:

    • "YesNo": keys Y and N, values Yes and No
    • "YesNo - History": keys Yes and No, values Yes and No
    • "TrueFalse": keys T and F, values True and False
    • "YNList": keys y and n, values y and n
    • "yesno": keys y and n, values y and n
    • "YesNo - Copy: keys 1 and 0, values Yes and No
    • "YN": keys Y and N, values Yes and No
    • "Yes/No": keys 1 and 2, values Yes and No
    • "YesNo - Alerts": keys Yes and No, values Yes and No

    That's what happens when you let business analysts loose on software design.

  • (disco) in reply to Quite

    Gah!

    That is one bad pile of #¤&/¤#.........

    I pity the one who have to compare between any of those 'styles'.....

  • (disco)
  • (disco)

    So.... equivalent_values(true, true) gives false....?

  • (disco)

    Lisa worked on Discourse?

  • (disco)
     private static long truthiness = 0L;
     public static boolean Truthiness(boolean test)
     {
         return (test ? ++truthiness : --truthiness) > 0L;  // thread saftey: meh
     }
    

    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."

  • (disco) in reply to CoyneTheDup
    CoyneTheDup:
     private static long truthiness = 0L;
     public static boolean Truthiness(boolean test)
     {
         return (test ? ++truthiness : --truthiness) > 0L;  // thread saftey: meh
     }
    

    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."

    I... That... That's horrible. Why would you ever do that? AAAAAAAAAAAUUUUUUUUUUUUUUGGGGGHHHHHHHHH

  • (disco) in reply to sloosecannon
    sloosecannon:
    I...That...That's horrible.Why would you ever do that?AAAAAAAAAAAUUUUUUUUUUUUUUGGGGGHHHHHHHHH

    Because some idiot overly clever authoridiot made up the words "truthy" and "truthiness" for an article?

    I 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."

  • (disco) in reply to sloosecannon
    sloosecannon:
    Why would you ever do that?

    Yeah. You should definitely use BigInteger instead of long.

  • (disco)

    The truth??

    You can't handle the truth!!

    Look, somebody had to do it.

  • (disco) in reply to herby
    herby:
    The truth??

    You can't handle the truth!!

    Will the new forum have a dislike button?

Leave a comment on “The Coercive Types”

Log In or post as a guest

Replying to comment #:

« Return to Article