• Tsaukpaetra (disco)

    I kinda like being on the before-everyone-else-gets-it train.... But also a little guilty for those not in the know? TBH I probably would have expected an IF...ELSEIF...END cascade. :fa_thumbs_down: for originality?

  • HardwareGeek (disco) in reply to Tsaukpaetra
    Tsaukpaetra:
    little guilty for those not in the know

    Nah, this is not exactly secret. If people aren't in the know, it's pretty much their own fault.

    As for the article, itself, there are two explanations, either or some combination of both of which may be involved: 1. Incompetent people are incompetent. 2. Even competent people occasionally write dumb code.

    Filed under: Of course, these explanations apply to most code snippets we see here.

  • PJH (disco)
    Comment held for moderation.
  • Medinoc (disco)

    I'm not sure I see the WTF in the '<scr'+ 'ipt' one. Isn't it standard practice when you need to write a script from inside a <script> tag, because otherwise the HTML parser screws you over?

    Of course, dynamically linking to a script from client side might be TRWTF.

    Edit: I've broken Discourse! Corrected by replacing angular brackets with HTML enbreasties.

  • Sergio_Bastos (disco)
    Comment held for moderation.
  • Shoreline (disco)
    We pick on date handling code a lot here, simply because there are so many ways to mess up date related code...

    Most of which seem to be easily fixed by using a suitable library.

    document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></sc'+'ript>');
    
    Sergio_Bastos:
    Actually, this is a well known problem in the html spec...

    Alas, Hanzo'd by 17 minutes.

  • PJH (disco)

    This topic is now listed. It will be displayed in topic lists.

  • jam13c (disco)

    On the last one, I'm afraid you're TRWTF for not understanding the problem.

  • accalia (disco) in reply to PJH
    PJH:
    This topic is now listed. It will be displayed in topic lists.

    .... PAULA!

    slacking off on the job again is she....\

    why i aughta make a version of SockBot to take her job from her and work a bilionty times better!

  • CoyneTheDup (disco)

    First off the bat...

    boolean isPaymentType = false;
    for (int i = 100; i < 199; i++) {
        if (telegramType == i) {
            isPaymentType = true;
        }
    }
    

    I don't know what everyone is smoking, but this works (and works and works and works) for 100 through 198. 199 is feeling left out...

    Addendum

    You know what? Not only that, but this just doesn't feel....enterprisey enough. He needs to create an array and put his list of valid values in the array, then do foreach on the array elements. That way, it can be wrong in the enterprisey way.

  • dkf (disco) in reply to CoyneTheDup
    CoyneTheDup:
    I don't know what everyone is smoking, but this works (and works and works and works) for 100 through 198. 199 is feeling left out...

    It does have the dubious advantage of taking virtually the same amount of time whether the test succeeds or fails. [spoiler]And proving that the creator of the code is a nincompoop.[/spoiler]

    CoyneTheDup:
    He needs to create an array and put his list of valid values in the array, then do foreach on the array elements.

    Perhaps he should also fetch the valid values from a database?

  • PWolff (disco) in reply to CoyneTheDup

    This isn't enterprisey enough either.

    (Please imagine the following code correctly indented and without line breaks, didn't find a way to copy and paste and don't have a keystroke simulator handy)

    boolean isPaymentType;
    if (telegramType == 100) {
      isPaymentType = true;
    } elseif (telegramType == 101) {
      isPaymentType = true;
    } elseif (telegramType == 102) {
      isPaymentType = true;
    } elseif (telegramType == 101) {
      isPaymentType = true;
    /* omitted 195 lines of code - no, the 101 is no typo, it's part of the enterpriseyness */
    } elseif (telegramType == 198) {
      isPaymentType = true;
    } elseif (telegramType > 200) {
      isPaymentType = false;
    };
    

    Or we could make use of a nested loop, for nested loops are cool

  • Mario_Levesque (disco)

    Sorry.. no sorry this has to be the biggest WTF piece of code.. ever..

    boolean isPaymentType = false;
    for (int i = 100; i < 199; i++) {
        if (telegramType == i) {
            isPaymentType = true;
        }
    }
    

    You have to WANT IT to be that way to come up with this.. its like intentionally put the key in the safe to be sure not to lose it.

    It hurts my brain just to find an excuse for the poor f*ck..

  • Mario_Levesque (disco) in reply to CoyneTheDup

    No it doesnt work, Coyne. It would work only if the telegramtype is 198. Otherwise, it'll always be false.

  • PWolff (disco) in reply to dkf
    dkf:
    fetch the valid values from a database

    Now that's the TRUE enterprise spirit!

    It's the easiest way to enable the user to extend the range by adding a few records to the database. Via a copied and custom-made web interface. No need to worry about SQL injection, of course.

  • FullPointerException (disco) in reply to dkf
    dkf:
    Perhaps he should also fetch the valid values from a database?

    Yes, but they should be stored as strings, complete with handrolled integer to string conversions

  • Mario_Levesque (disco) in reply to PWolff
    PWolff:
    No need to worry about SQL injection, of course.

    Why would we? Nobody will try to do that? i mean.. right?

  • PWolff (disco) in reply to Mario_Levesque
    Mario_Levesque:
    It would work only if the telegramtype is 198. Otherwise, it'll always be false.

    The assignment to false is done before the loop only.

    But you're right in that putting that into the loop would be even more enterprisey. Best like

    if (telegramType == i) {
        isPaymentType = (telegramType == i);
    } else {
        isPaymentType = (telegramType == i);
    };
    
  • CarrieVS (disco)

    I came across an if statement a while ago which tested

    if ( $condition || ! $condition )

  • PWolff (disco) in reply to FullPointerException
    FullPointerException:
    complete with handrolled integerfloat to string conversions

    This way it's way more extendable.

  • Mario_Levesque (disco) in reply to PWolff

    Spot on.. my bad on the false thingy.. but your solution is more elegant.. enterprisey wise.. :smile:

  • Mario_Levesque (disco) in reply to CarrieVS

    if ( $condition || ! $condition )

    To be or not to be. That is the condition..

  • dkf (disco) in reply to CarrieVS

    As opposed to:

    if ( $condition || $condition || $condition )
    

    ?

  • FullPointerException (disco) in reply to PWolff
    PWolff:
    This way it's way more extendable.

    Actually, why not roll our own Number class, that way we aren't limited by the precision or ranges of built in types?

  • dkf (disco) in reply to FullPointerException
    FullPointerException:
    why not roll our own Number class

    Done that. It's a lot of work to do right.

  • CarrieVS (disco) in reply to dkf

    At least the actual if statement isn't totally redundant there, only two of the conditions.

  • FullPointerException (disco) in reply to dkf

    In all seriousness, I completely agree.

    Although in the concept of making things as wtf-y as possible, I think it's 100% necessary to do. Like that time my manager wanted me to write my own list implementation, just in case there was a bug in std::list.

  • Eldelshell (disco) in reply to FullPointerException

    That's easy:

    // Because of stupid boss
    class MyList : public std::list<MyObject>{};
    
  • grkvlt (disco) in reply to Mario_Levesque

    Boring, everyone goes for the Hamlet conditional. Inspired by:

    dkf:
    if ( $condition || $condition || $condition )

    Let's try Macbeth instead!

    boolean condition = Date.daysBetween(Date.now(), targetDate) == 1; // tomorrow?
    if (condition && condition && condition) {
        while (true) {
            // To the last syllable of recorded time
        }
    }
    
  • george_gonzalez (disco) in reply to Mario_Levesque

    we can speed up the loop with a clever:

    telegramType = telegramType | telegramType == i;

    Still.....

  • dkf (disco) in reply to george_gonzalez
    george_gonzalez:
    isPaymentType = isPaymentType | telegramType == i;

    FTFY…

  • kupfernigk (disco) in reply to Tsaukpaetra
    Tsaukpaetra:
    TBH I probably would have expected an IF...ELSEIF...END cascade. for originality?

    I wonder if, in the world of failed "4th and 5th generation programming languages", there is one that might have generated that code. Having seen the dumb queries that Access generates, nothing would surprise me.

  • grkvlt (disco) in reply to dkf

    Or, for brevity and/or obscurity isPaymentType |= telegramType == i if your language supports it?

  • kupfernigk (disco) in reply to dkf
    dkf:
    Perhaps he should also fetch the valid values from a database?

    create table telegramtype { smallint id NOT NULL PRIMARY KEY, nvarchar(254) id_description NOT NULL, boolean is_telegramtype DEFAULT false, creationdate datetime DEFAULT CURRENT_TIMESTAMP } INSERT INTO telegramtype(id,id_description,is_telegramtype)VALUES(100, 'some significance',true); INSERT INTO telegramtype(id, id_description, is_telegramtype)VALUES(101,'a different significance',true); /code omitted/ .....("SELECT is_telegramtype FROM telegramtype WHERE id = ?",id);

    This is properly enterprisy because it is necessary to test for null as well as false. I am sure a decent system architect could get the telegramtype table up to a lot more fields. How about a modification date and the creator username?

    All added value....

  • Vault_Dweller (disco) in reply to kupfernigk

    Not necessarily more fields, but a proper "audit trail" table might do the trick

  • Dragnslcr (disco)
    boolean isPaymentType = false; for (int i = 100; i < 199; i++) { if (telegramType == i) { isPaymentType = true; } }

    Well, you know, this also checks that telegramType is an integer in the range. Just checking for >= 100 and <=199 would also include values like 123.5. And we can't be having that.

  • kupfernigk (disco) in reply to Vault_Dweller
    Vault_Dweller:
    Not necessarily more fields, but a proper "audit trail" table might do the trick

    Yes, I wasn't thinking Enterprise enough. Also we should log all queries on the table to check for invalid telegramtypes that might need to be added later.

  • machtyn (disco)

    Okay, please correct me if I'm wrong. I'm only a moderate programmer, but I learn quickly. I've been hounding my international team for constantly writing:

    if (conditional == true) { // do true stuff }
    

    Seriously, if it's true, just leave it as the conditional!

    if (conditional) { // do true stuff }
    

    I would hope the compiler optimizes that out, but it just looks weird to me.

  • Mikerad1979 (disco) in reply to kupfernigk

    Not enough XML fields in that table...

  • Frykun (disco)
    document.write('<sc'+'ript language="javascript" type="text/javascript" src="' + url + '"></sc'+'ript>');
    

    There are actually good reasons for this insanity! It all has to do with how browsers parse and interpret the JS. Mostly IE's fault, really...

    Suppose you're writing a 3rd party script for pages, a tracking pixel

    <script>document.write...
    

    document.write makes sure your next script is injected immediately after current script -- instead of parsing the rest of HTML beforehand (synchronous JS import). It's a bad idea to use this since it will make the page load slower, but there it is.

    Since it's a tracking pixel, you don't want it firing unless the user is actually looking at the page. If you leave the string unbroken, '<script src="...' -- the browser's prefetcher will download the script before your inline script is executed!

    ...so you curse your job for making you create a tracking pixel, and do what hundreds of devs had done before....

  • DJSpudplucker (disco) in reply to Dragnslcr

    Am I the only one to see what's wrong?

    boolean isPaymentType = false;
    for (int i = 100; i < 199; i++) {
        if (telegramType == i) {
            isPaymentType = true;
            break;
        }
    }
    

    FTFY.

  • kupfernigk (disco) in reply to Mikerad1979
    Mikerad1979:
    Not enough XML fields in that table

    Also I missed out a suitably weird collation and a table descriptor.I'm just not trying, am I?

  • kupfernigk (disco) in reply to DJSpudplucker
    DJSpudplucker:
    FTFY.

    But now it won't run in more or less constant time, which may be a desired feature.

  • Mikael_Svahnberg (disco) in reply to PJH
    Comment held for moderation.
  • dcon (disco) in reply to PWolff
    PWolff:
    /* omitted 195 lines of code - no, the 101 is no typo, it's part of the enterpriseyness */

    But you need to list them all! Otherwise how do you show that you missed 142?

  • narbat (disco)

    It's possible (thought pretty bloody unlikely) that telegramType is an instance of some sort of custom class that defines an equality test with integers, but isn't sortable. I could see it being done for some kind of enumeration class for which greater-than and less-than operators don't make sense. Of course, if that's what this is TRWTF is why such an oddball class doesn't have its own methods for figuring out if it's a payment type.

  • narbat (disco) in reply to machtyn
    machtyn:
    Okay, please correct me if I'm wrong. I'm only a moderate programmer, but I learn quickly. I've been hounding my international team for constantly writing:

    if (conditional == true) { // do true stuff }

    Seriously, if it's true, just leave it as the conditional!

    if (conditional) { // do true stuff }

    I would hope the compiler optimizes that out, but it just looks weird to me.

    A lot of languages will implicitly convert any expression to a boolean, so "if (condition)" will evaluate as true if condition is a non-zero integer, a non-empty string, etc. That's usually what you want, but maybe you actually want to know if the conditional is actually a boolean with the value true and you want it return false for any normally truthy value that's not strictly boolean true. If that's the case though, you probably ought to be explicit about it. "if (type(conditional) == boolean && conditional == true) {...}"

  • DJSpudplucker (disco) in reply to kupfernigk
    kupfernigk:
    DJSpudplucker:
    FTFY.

    But now it won't run in more or less constant time, which may be a desired feature.

    Oh dear, you're right! There must be some way to improve it?

  • CoyneTheDup (disco) in reply to kupfernigk
    Mario_Levesque:
    No it doesnt work, Coyne. It would work only if the telegramtype is 198. Otherwise, it'll always be false.

    No, it only changes isPaymenType if it finds a match. So it will work for any of the 99 values of i...it's just that the values of i that are tested only go from 100 to 198.

    PWolff:
    But you're right in that putting that into the loop would be even more enterprisey. Best like

    if (telegramType == i) { isPaymentType = (telegramType == i); } else { isPaymentType = (telegramType == i); };

    I think that makes it worse...if that were possible....

    CarrieVS:
    I came across an if statement a while ago which tested

    if ( $condition || ! $condition )

    Well, of course they tested it that way. Must account for FILE_NOT_FOUND.

    kupfernigk:
    create table telegramtype ... etc.

    This is properly enterprisy because it is necessary to test for null as well as false. I am sure a decent system architect could get the telegramtype table up to a lot more fields. How about a modification date and the creator username?

    All added value....

    You're right...that's the way it really should be done. That's the true enterprisey.

  • isthisunique (disco)
    Comment held for moderation.

Leave a comment on “If You Want To”

Log In or post as a guest

Replying to comment #:

« Return to Article