Useless Functions, Extreme Naming, and More

« Return to Article
  • twitter 2011-10-30 21:57
    frist. hope the 12$ was worth it Alex!

    CAPTCHA: nulla. if(obj == nulla) { return ""a;}
  • anon 2011-10-31 09:05
    twitter:
    frist. hope the 12$ was worth it Alex!

    CAPTCHA: nulla. if(obj == nulla) { return ""a;}
    You're not only first, you commented 11 hours before the article was posted! #ninja
  • Matt Westwood 2011-10-31 09:06

    writtenComment() {
    return true;
    }
  • The Mr. T Experience 2011-10-31 09:10
    TRWTF is listing "French" and "Gay" separately.
  • BentFranklin 2011-10-31 09:27
    In the 8th one the camel case is wrong. It should be:

    public override void ManagerElations()
  • Gay 2011-10-31 09:28
    TRWTF is listing my name and your name separately.
  • Nagesh 2011-10-31 09:29
    First time I see use of generic in code

    Is this production redy code?
  • Alex 2011-10-31 09:38
    You know, I think the last one is used in the DB/IDE we use at work: one of the syntax error message reads "You are missing a '*', a '*', an expression or a '*'"

    Glad to hear the original coder of that statement found a job elsewhere
  • Fishertroll 2011-10-31 09:52
    // 10/31/00 - removing voter registration duplicate verification
    // ** this could be part of the reason that we
    // ** have been represented so poorly lately
  • boog 2011-10-31 09:53
    private var languageLabels:ArrayCollection = new ArrayCollection(
    
    "English",
    "German",
    "French",
    "Zunesis"
    );
    FTFY
  • trtrwtf 2011-10-31 10:10
    The Article:
    /// <summary>
    /// Log the user off the system. The method returns true or false for success or failure
    /// </summary>
    public bool Logoff(string strUser)
    {
    return true;
    }


    At least the comment is correct.
  • Deus 2011-10-31 10:26
    Hey! I speak Gay.
  • evilspoons 2011-10-31 10:28
    Looks like someone took their CS course explaining "magic numbers are bad" literally instead of in spirit.

    I can see it being very important to change everything that says it uses X number of parameters to actually use Y.
  • Matt Westwood 2011-10-31 10:35
    Matt Westwood:

    writtenComment() {
    return THIS.IS.HOW.TO.WRITE.A.comment();
    }
  • airdrik 2011-10-31 10:40
    Obviously, the problem is with the abbreviated names in the hierarchy. They would be so much more readable if they were just spelled out:

    String yyyyMMdd = "yyyyMMdd"
    // get account information
    m_bankID = ofx.BANKMESSAGESERVICE1.STATEMENTTRANSACTIONSRESULTSET.STATEMENTRESULTSET.BANKACCOUNTFROM.BANKID;
    m_accountID = ofx.BANKMESSAGESERVICE1.STATEMENTTRANSACTIONSRESULTSET.STATEMENTRESULTSET.BANKACCOUNTFROM.ACCOUNTID;
    m_accountType = ofx.BANKMESSAGESERVICE1.STATEMENTTRANSACTIONSRESULTSET.STATEMENTRESULTSET.BANKACCOUNTFROM.ACCOUNTTYPE.ToString(); // this is an enum; convert to string

    // get start and end dates of statement
    m_startDate = DateTime.ParseExact(ofx.BANKMESSAGESERVICE1.STATEMENTTRANSACTIONSRESULTSET.STATEMENTRESULTSET.BANKTRANSACTIONSLIST.DATESTART, yyyyMMdd, System.Globalization.CultureInfo.InvariantCulture);
    m_endDate = DateTime.ParseExact(ofx.BANKMESSAGESERVICE1.STATEMENTTRANSACTIONSRESULTSET.STATEMENTRESULTSET.BANKTRANSACTIONSLIST.DATEEND, yyyyMMdd, System.Globalization.CultureInfo.InvariantCulture);

    // get closing balance and date this refers to
    m_closingBalance = moneyInPenceFromString(ofx.BANKMESSAGESERVICE1.STATEMENTTRANSACTIONSRESULTSET.STATEMENTRESULTSET.LEDGERBALANCE.BALANCEAMOUNT);
    m_closingBalanceDate = DateTime.ParseExact(ofx.BANKMESSAGESERVICE1.STATEMENTTRANSACTIONSRESULTSET.STATEMENTRESULTSET.LEDGERBALANCE.DATEASOF, yyyyMMdd, System.Globalization.CultureInfo.InvariantCulture);

    m_transactions = new System.Collections.Generic.List<OfxTransaction>();
    foreach (SimpleOfx.OFXBANKMESSAGESERVICE1STATEMENTTRANSACTIONSRESULTSETSTATEMENTRESULTSETBANKTRANSACTIONSLISTSTATEMENTTRANSACTION transactionStatementNode in ofx.BANKMESSAGESERVICE1.STATEMENTTRANSACTIONSRESULTSET.STATEMENTRESULTSET.BANKTRANSACTIONSLIST.STATEMENTTRANSACTION)
    {
    m_transactions.add(new OfxTransaction(
    moneyInPenceFromString(transactionStatementNode.TRANSACTIONAMOUNT),
    DateTime.ParseExact(transactionStatementNode.DATEPOSTED, yyyyMMdd, System.Globalization.CultureInfo.InvariantCulture),
    transactionStatementNode.NAME,
    transactionStatementNode.TRANSACTIONTYPE.ToString(),
    transactionStatementNode.MEMO)
    );
    }

    There, so much more readable!
  • AerieC 2011-10-31 10:40
    SimpleOfx.OFXBANKMSGSRSV1STMTTRNRSSTMTRSBANKTRANLISTSTMTTRN


    It seems to me that SimpleOfx is anything but simple, but I'll take a stab at this one:

    OFX Bank message server 1 statement turn rss teenage mutant ninja turtle real super bank transaction list status teenage mutant ninja turtle transmission.

    Do I win?

    (Captcha: opto. This property makes my opto nerve hurt.)
  • airdrik 2011-10-31 10:45
    AerieC:
    SimpleOfx.OFXBANKMSGSRSV1STMTTRNRSSTMTRSBANKTRANLISTSTMTTRN


    It seems to me that SimpleOfx is anything but simple, but I'll take a stab at this one:

    OFX Bank message seriously version 1 statement turn rss teenage mutant turtle real super bank transaction list status teenage mutant turtle transmission.

    Do I win?

    (Captcha: opto. This property makes my opto nerve hurt.)

    ftfy
  • Coyne 2011-10-31 10:46
    I've seen something similar to the last in a COBOL code section here:

    IF SOME-VAR = ZERO OR
    SOME-VAR = ZEROES

    Clearly someone who didn't understand that, in COBOL, ZERO and ZEROES are just different ways of saying the same thing.
  • Utterly Confused 2011-10-31 10:53
    >#define TASK_RATE_ONE_SECOND (TASK_RATE * 40)

    What would this mean, the number of TASK_RATE tasks in one second? If so, yeah, this is 200 for a TASK_RATE of 5 ms BUT it should be computed as 1000/TASK_RATE ***CONFUSED***
  • Bronie 2011-10-31 10:54
    This is exactly reason why I don't like foreach - var tends to lose context.

    What it should look like:

    foreach (SimpleOfx.OFXBANKMSGSRSV1STMTTRNRSSTMTRSBANKTRANLISTSTMTTRN ofxbankmsgsrsv1stmttrnrsstmtrsbanktranliststmttrn in ofx.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKTRANLIST.STMTTRN)
    
    {
    m_transactions.Add(new OfxTransaction(
    moneyInPenceFromString(ofxbankmsgsrsv1stmttrnrsstmtrsbanktranliststmttrn.TRNAMT),
    DateTime.ParseExact(ofxbankmsgsrsv1stmttrnrsstmtrsbanktranliststmttrn.DTPOSTED, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture),
    ofxbankmsgsrsv1stmttrnrsstmtrsbanktranliststmttrn.NAME,

    ofxbankmsgsrsv1stmttrnrsstmtrsbanktranliststmttrn.TRNTYPE.ToString(), ofxbankmsgsrsv1stmttrnrsstmtrsbanktranliststmttrn.MEMO)
    );
    }
  • C-Octothorpe 2011-10-31 10:58
    That last one is eerily similar to the code-base I inherited about a year ago, except replace all the "safe" if blocks with try/catch blocks...
    public static int StringToInt32(string str)
    
    {
    try {
    return int.parse(str);
    }
    catch { return 0; }
    }
    Ahh, now that's a beaute! Or the single return variant:
    public static int StringToInt32(string str)
    
    {
    itn returnValue = "";

    try {
    returnValue = int.parse(str);
    }
    catch { }

    return returnValue;
    }
    Now if this "pattern" doesn't scream "I don't give a shit about the quality of my code", then I don't know what does...
  • C-Octothorpe 2011-10-31 11:00
    boog:
    private var languageLabels:ArrayCollection = new ArrayCollection(
    
    "English",
    "German",
    "French",
    "Zunesis"
    );
    FTFY
    Oh silly me. I thought that was a list of languages, not genders... My bad.
  • milleniumbug 2011-10-31 11:03
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!
  • Matt Westwood 2011-10-31 11:06
    C-Octothorpe:
    boog:
    private var languageLabels:ArrayCollection = new ArrayCollection(
    
    "English",
    "German",
    "French",
    "Zunesis"
    );
    FTFY
    Oh silly me. I thought that was a list of languages, not genders... My bad.


    +1

    In order of presentation: "Male", "Neuter", "Female", "Indeterminate"?
  • geocities 2011-10-31 11:07
    The GetStringValue example is not a WTF, but just the result of thinking about the same cases (reference could be NULL) multiple times.

    I frequently get this when I code via automatic electroencephalography input and lose concentration for a while. Most cases are caught by the optimizer; but sometimes, garbage slips through. The optimizer removes it usually, but not always. I frequently get this when I code via automatic electroencephalography input and lose concentration for a while.
  • Bronie 2011-10-31 11:09
    Matt Westwood:


    +1

    In order of presentation: "Male", "Neuter", "Female", "Indeterminate"?


    "Both".

    Captcha: vulputate
  • Zune-Tran 2011-10-31 11:09
    boog:
    private var tongueLabias:ArrayCollection = new ArrayCollection(
    
    "English",
    "German",
    "French",
    "Zunesis"
    );
    FTFY
    ZFTY
  • Matt Westwood 2011-10-31 11:29
    Bronie:
    Matt Westwood:


    +1

    In order of presentation: "Male", "Neuter", "Female", "Indeterminate"?


    "Both".

    Captcha: vulputate


    You wish.
  • catdog 2011-10-31 11:31
    The one from Ryan is not a WTF. The method may just return now, but could easily be a hook for something that needs to be done for the future. The try/catch is probably something they require as part of a process for all of their methods, and it's better to do it in advance than not do it, so later when someone makes the method do something, not only do they have to remember their task but they have to remember to add the try/catch when that's something they never have to do for an existing method. It's the same reason why coding standards saying to use curly braces on single line statements: because why make someone remember they have to do it later when you could just mitigate the risk and do it now.
  • Matt Westwood 2011-10-31 11:42
    catdog:
    The one from Ryan is not a WTF. The method may just return now, but could easily be a hook for something that needs to be done for the future. The try/catch is probably something they require as part of a process for all of their methods, and it's better to do it in advance than not do it, so later when someone makes the method do something, not only do they have to remember their task but they have to remember to add the try/catch when that's something they never have to do for an existing method. It's the same reason why coding standards saying to use curly braces on single line statements: because why make someone remember they have to do it later when you could just mitigate the risk and do it now.


    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.
  • geoffrey 2011-10-31 11:46
    m_accountType = ofx.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKACCTFROM.ACCTTYPE.ToString()


    The Only WTF is that they didn't leave the application in COBOL in the first place, but tried to convert it to C.

    In COBOL you don't have to write out the full parentage of a nested field like that, or have to bother with the ToString(). You would just write:

    move ACCTTYPE to M-ACCOUNT-TYPE

  • Steve The Cynic 2011-10-31 11:48
    milleniumbug:
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!

    Nothing wrong with comments in a #define.

    However, in the real world, "rates" are measured in Hz, not seconds. It should be TASK_INTERVAL or TASK_PERIOD or something like that.

    Well, assuming it really is in milliseconds, that is, and not work-units per unit of time.
  • iToad 2011-10-31 11:52
    geoffrey:
    m_accountType = ofx.BANKMSGSRSV1.STMTTRNRS.STMTRS.BANKACCTFROM.ACCTTYPE.ToString()


    The Only WTF is that they didn't leave the application in COBOL in the first place, but tried to convert it to C.

    In COBOL you don't have to write out the full parentage of a nested field like that, or have to bother with the ToString(). You would just write:

    move ACCTTYPE to M-ACCOUNT-TYPE



    So it has come to this... COBOL has become a better alternative than Java or C. That's just sad.
  • frits 2011-10-31 11:57
    Steve The Cynic:
    milleniumbug:
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!

    Nothing wrong with comments in a #define.

    However, in the real world, "rates" are measured in Hz, not seconds. It should be TASK_INTERVAL or TASK_PERIOD or something like that.

    Well, assuming it really is in milliseconds, that is, and not work-units per unit of time.


    const int NUM_MILLISECONDS = 20;
    ...
    int wtf = TASK_RATE * NUM_MILLISECONDS;
    cout << wtf << endl;


    output: 5
    ???


    Addendum (2011-10-31 12:03):
    EDIT: My misconception, sorry. Steve is absolutely correct. At least I can leave pretty code to harrass those who like monochromatic comments. :P
  • trtrwtf 2011-10-31 12:00
    Matt Westwood:

    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.


    Style is fashion - do what everyone on your project does, it'll be okay.
    K&R is popular in books because vertical line space is expensive in print. On the screen, vertical line space is free, and if it's an issue it's an alarm bell: time to refactor.

    I prefer the One True Brace Style (Allman style) because it lets me line up the braces by eye, and makes the blocks more obvious. But whatever, in this world there are certainly bigger things to get worked up about.
    Single-line braces are a belt-and-suspenders thing, at best. If you're doing everything else right, they don't make a lot of difference, and they busy up your code. If you're doing everything else wrong, they're not likely to make a lot of difference, and they busy up your code. So don't bother, I say, just do everything else right.
  • geoffrey 2011-10-31 12:13
    trtrwtf:
    Matt Westwood:

    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.


    Style is fashion - do what everyone on your project does, it'll be okay.
    K&R is popular in books because vertical line space is expensive in print. On the screen, vertical line space is free, and if it's an issue it's an alarm bell: time to refactor.

    I prefer the One True Brace Style (Allman style) because it lets me line up the braces by eye, and makes the blocks more obvious. But whatever, in this world there are certainly bigger things to get worked up about.
    Single-line braces are a belt-and-suspenders thing, at best. If you're doing everything else right, they don't make a lot of difference, and they busy up your code. If you're doing everything else wrong, they're not likely to make a lot of difference, and they busy up your code. So don't bother, I say, just do everything else right.


    Reminds me of a job I had 15 years ago. I was moved onto a long running project and found myself on the "team" of a real bunch of K&R apologists. Despite my best attempts to educate them as to the merits of single line quotes they forced me to use K&R. Joke was on them though, each day I would secretly convert pieces of the code from K&R to single brace (as well as making some other more aesthetic and functional changes/improvements). Then when they went home each night I would disable the source control notification system, force commit my changes (ie overwrite the repository - this was long before CVS even) and renable the system again.

    Slowly but surely the whole code base was improved (from the most obscure files upwards) and by the time they realized what had happened (weeks later) it was already too late to change it back.
  • G-Spot 2011-10-31 12:19
    foreach(comment.THATMAYHAVESOMEINTERESTINGCONTENT in comments.FROMTHEDAILYWTFFRONTPAGE)
    
    {
    if(user.SOCKPUPPETNAME.equals("geoffrey")
    {
    igsnore();
    }

    }
  • Matt Westwood 2011-10-31 12:26
    geoffrey:
    trtrwtf:
    Matt Westwood:

    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.


    Style is fashion - do what everyone on your project does, it'll be okay.
    K&R is popular in books because vertical line space is expensive in print. On the screen, vertical line space is free, and if it's an issue it's an alarm bell: time to refactor.

    I prefer the One True Brace Style (Allman style) because it lets me line up the braces by eye, and makes the blocks more obvious. But whatever, in this world there are certainly bigger things to get worked up about.
    Single-line braces are a belt-and-suspenders thing, at best. If you're doing everything else right, they don't make a lot of difference, and they busy up your code. If you're doing everything else wrong, they're not likely to make a lot of difference, and they busy up your code. So don't bother, I say, just do everything else right.


    Reminds me of a job I had 15 years ago. I was moved onto a long running project and found myself on the "team" of a real bunch of K&R apologists. Despite my best attempts to educate them as to the merits of single line quotes they forced me to use K&R. Joke was on them though, each day I would secretly convert pieces of the code from K&R to single brace (as well as making some other more aesthetic and functional changes/improvements). Then when they went home each night I would disable the source control notification system, force commit my changes (ie overwrite the repository - this was long before CVS even) and renable the system again.

    Slowly but surely the whole code base was improved (from the most obscure files upwards) and by the time they realized what had happened (weeks later) it was already too late to change it back.


    What a shitty thing to do.
  • trtrwtf 2011-10-31 12:29
    Matt Westwood:
    geoffrey:
    trtrwtf:
    Matt Westwood:

    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.


    Style is fashion - do what everyone on your project does, it'll be okay.
    K&R is popular in books because vertical line space is expensive in print. On the screen, vertical line space is free, and if it's an issue it's an alarm bell: time to refactor.

    I prefer the One True Brace Style (Allman style) because it lets me line up the braces by eye, and makes the blocks more obvious. But whatever, in this world there are certainly bigger things to get worked up about.
    Single-line braces are a belt-and-suspenders thing, at best. If you're doing everything else right, they don't make a lot of difference, and they busy up your code. If you're doing everything else wrong, they're not likely to make a lot of difference, and they busy up your code. So don't bother, I say, just do everything else right.


    Reminds me of a job I had 15 years ago. I was moved onto a long running project and found myself on the "team" of a real bunch of K&R apologists. Despite my best attempts to educate them as to the merits of single line quotes they forced me to use K&R. Joke was on them though, each day I would secretly convert pieces of the code from K&R to single brace (as well as making some other more aesthetic and functional changes/improvements). Then when they went home each night I would disable the source control notification system, force commit my changes (ie overwrite the repository - this was long before CVS even) and renable the system again.

    Slowly but surely the whole code base was improved (from the most obscure files upwards) and by the time they realized what had happened (weeks later) it was already too late to change it back.


    What a shitty thing to do.


    What, you mean responding to a troll?
  • Steve The Pirate 2011-10-31 12:29
    C-Octothorpe:
    That last one is eerily similar to the code-base I inherited about a year ago, except replace all the "safe" if blocks with try/catch blocks...
    public static int StringToInt32(string str)
    
    {
    try {
    return int.parse(str);
    }
    catch { return 0; }
    }
    Ahh, now that's a beaute! Or the single return variant:
    public static int StringToInt32(string str)
    
    {
    int returnValue = "";

    try {
    returnValue = int.parse(str);
    }
    catch { }

    return returnValue;
    }
    Now if this "pattern" doesn't scream "I don't give a shit about the quality of my code", then I don't know what does...

    That is an interesting value to initialize your int to
  • Severity One 2011-10-31 12:31
    The Mr. T Experience:
    TRWTF is listing "French" and "Gay" separately.
    You are obviously unfamiliar with Alizée.
  • Tyler Durdin 2011-10-31 12:37

    public static string GetStringValue(object obj)
    {
    if (obj == null)
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    if (!(obj == null))
    {
    return obj.ToString();
    }
    else
    {
    return "";
    }
    }


    The first rule of GetStringValue is return "" for (obj == null).
    The second rule of GetStringValue is return "" for (obj == null)!
    The third rule of GetStringValue is if !(obj == null) - you HAVE to fight.
  • The Mr. T Experience 2011-10-31 12:38
    Severity One:
    The Mr. T Experience:
    TRWTF is listing "French" and "Gay" separately.
    You are obviously unfamiliar with Alizée.
    Do you mean the singer? Why? because you think she's hot? I suppose you also think that Harry potter movies aren't gay because you have a crush on that little girl Emma what's-her-name?
  • PedanticCurmudgeon 2011-10-31 12:39
    Matt Westwood:
    C-Octothorpe:
    boog:
    private var languageLabels:ArrayCollection = new ArrayCollection(
    
    "English",
    "German",
    "French",
    "Zunesis"
    );
    FTFY
    Oh silly me. I thought that was a list of languages, not genders... My bad.
    +1

    In order of presentation: "Male", "Neuter", "Female", "Bored Teenager with nothing better to do."
    FTFY
  • C-Octothorpe 2011-10-31 12:39
    Steve The Pirate:
    C-Octothorpe:
    That last one is eerily similar to the code-base I inherited about a year ago, except replace all the "safe" if blocks with try/catch blocks...
    public static int StringToInt32(string str)
    
    {
    try {
    return int.parse(str);
    }
    catch { return 0; }
    }
    Ahh, now that's a beaute! Or the single return variant:
    public static int StringToInt32(string str)
    
    {
    int returnValue = "";

    try {
    returnValue = int.parse(str);
    }
    catch { }

    return returnValue;
    }
    Now if this "pattern" doesn't scream "I don't give a shit about the quality of my code", then I don't know what does...

    That is an interesting value to initialize your int to
    I tried CTRL-SHIFT-B-ing the text editor, but it didn't report any build errors.

    I blame Obama, really...
  • Dave 2011-10-31 12:43
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?
  • Matt Westwood 2011-10-31 12:43
    trtrwtf:
    Matt Westwood:
    geoffrey:
    trtrwtf:
    Matt Westwood:

    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.


    Style is fashion - do what everyone on your project does, it'll be okay.
    K&R is popular in books because vertical line space is expensive in print. On the screen, vertical line space is free, and if it's an issue it's an alarm bell: time to refactor.

    I prefer the One True Brace Style (Allman style) because it lets me line up the braces by eye, and makes the blocks more obvious. But whatever, in this world there are certainly bigger things to get worked up about.
    Single-line braces are a belt-and-suspenders thing, at best. If you're doing everything else right, they don't make a lot of difference, and they busy up your code. If you're doing everything else wrong, they're not likely to make a lot of difference, and they busy up your code. So don't bother, I say, just do everything else right.


    Reminds me of a job I had 15 years ago. I was moved onto a long running project and found myself on the "team" of a real bunch of K&R apologists. Despite my best attempts to educate them as to the merits of single line quotes they forced me to use K&R. Joke was on them though, each day I would secretly convert pieces of the code from K&R to single brace (as well as making some other more aesthetic and functional changes/improvements). Then when they went home each night I would disable the source control notification system, force commit my changes (ie overwrite the repository - this was long before CVS even) and renable the system again.

    Slowly but surely the whole code base was improved (from the most obscure files upwards) and by the time they realized what had happened (weeks later) it was already too late to change it back.


    What a shitty thing to do.


    What, you mean responding to a troll?


    Good call. It was a knee-jerk reaction. He's a jerk, I kneed him.
  • C-Octothorpe 2011-10-31 12:47
    Matt Westwood:
    trtrwtf:

    What, you mean responding to a troll?
    Good call. It was a knee-jerk reaction. He's a jerk, I kneed him.
    +1

    *added to personal vocabulary*
  • Jerry 2011-10-31 12:51
    If those shagnasty long variable names didn't come from PeopleSoft, they must at least have been autogenerated by the same convert-mainframe-COBOL-directly-to-web-2.0 utility.
  • Bananas 2011-10-31 12:54
    Utterly Confused:
    >#define TASK_RATE_ONE_SECOND (TASK_RATE * 40)

    What would this mean, the number of TASK_RATE tasks in one second? If so, yeah, this is 200 for a TASK_RATE of 5 ms BUT it should be computed as 1000/TASK_RATE ***CONFUSED***
    Whoever created this mess fell into the all-too-common trap of using the word "rate" when he clearly meant "interval" instead. If you increase the value of that thing he named "rate" you will decrease the actual rate at which things happen.

    Does that help?
  • QJo 2011-10-31 12:57
    Dave:
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?


    I'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.

    The trick then is, after you *have* finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).
  • Matt Westwood 2011-10-31 12:59
    Severity One:
    The Mr. T Experience:
    TRWTF is listing "French" and "Gay" separately.
    You are obviously unfamiliar with Alizée.

    Oh yeah, France's answer to Kate Bush but without the talent.
  • Bananas 2011-10-31 13:07
    QJo:
    Dave:
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?


    I'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.

    The trick then is, after you *have* finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).
    Hrmmm.... troll or slacker?

    Yeah, sometimes just trying stuff at random is the only option left. But once you've found a random something that makes stuff work better, then you use that as a clue to resume your search for the real cause of the problem.

    In my book you haven't really fixed the problem until you can explain exactly why your change made things get better, and you have included that explanation as a comment in the code, rather than your whiny simpering complaint about lost hours.
  • C-Octothorpe 2011-10-31 13:12
    Bananas:
    In my book
    Highly unlikely...
  • Jay 2011-10-31 13:13
    Dave:
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?


    Good theory. I can just hear a programmer saying, "I KNOW this field is null. Why doesn't this test return true? Maybe I need to add parentheses ..."

    You'd think when we finally figured out whatever the problem was that he'd clean up the code. But then, maybe he never did figure it out, and once his poking and prodding got the program the work somehow, he was afraid to touch anything for fear the duct tape and rubber bands might break.
  • JL 2011-10-31 13:14
    Steve The Cynic:
    milleniumbug:
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!

    Nothing wrong with comments in a #define.

    ...



    Unless that #define is expanded in the middle of an expression! The latter half of the expression will be silently commented out. It might not even cause a syntax error, depending on where the next semicolon appears in subsequent lines of code.

    The effect is much like running Dissociated Press on your code.
  • Jay 2011-10-31 13:16
    Bananas:
    QJo:

    I'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.

    The trick then is, after you *have* finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).
    Hrmmm.... troll or slacker?

    Yeah, sometimes just trying stuff at random is the only option left. But once you've found a random something that makes stuff work better, then you use that as a clue to resume your search for the real cause of the problem.

    In my book you haven't really fixed the problem until you can explain exactly why your change made things get better, and you have included that explanation as a comment in the code, rather than your whiny simpering complaint about lost hours.


    But sometimes you never do figure it out. I'm not saying that's a desirable state, but that's how it is.

    The next worse thing after "It doesn't work and I have no idea why not" is "It does work and I have no idea why."
  • geoffrey 2011-10-31 13:22
    QJo:
    Dave:
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?


    I'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.

    The trick then is, after you *have* finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).


    you can probably tell a good programmer by what they don't try during a "let me try anything" stage.
  • Zune-Tran 2011-10-31 13:23
    C-Octothorpe:
    Bananas:
    In my book
    Highly unlikely...
    Why? I find it pretty easy to believe he has a book of "bananas" on his night stand. Right next to the box of tissues.
  • geoffrey 2011-10-31 13:29
    Zune-Tran:
    C-Octothorpe:
    Bananas:
    In my book
    Highly unlikely...
    Why? I find it pretty easy to believe he has a book of "bananas" on his night stand. Right next to the box of tissues.


    I once had a nightstand.
  • Ken B. 2011-10-31 13:29
    Alex:
    You know, I think the last one is used in the DB/IDE we use at work: one of the syntax error message reads "You are missing a '*', a '*', an expression or a '*'"

    Glad to hear the original coder of that statement found a job elsewhere
    Actually, there are three different possibilities for what's missing. Unfortunately, for security reasons, the list needed to be obscured.
  • Hortical 2011-10-31 13:30
    Bananas:
    Utterly Confused:
    >#define TASK_RATE_ONE_SECOND (TASK_RATE * 40)

    What would this mean, the number of TASK_RATE tasks in one second? If so, yeah, this is 200 for a TASK_RATE of 5 ms BUT it should be computed as 1000/TASK_RATE ***CONFUSED***
    Whoever created this mess fell into the all-too-common trap of using the word "rate" when he clearly meant "interval" instead. If you increase the value of that thing he named "rate" you will decrease the actual rate at which things happen.

    Does that help?
    Awww, man, don't even get me started - I hate fuckers! They make me want to strap them to the front of my car, go driving through head on traffic, and then stop, get out, ans as they begr for mercy, bring a cinder block down on their head! Smash their body into glop, spread it all over the ground and then lay down, move my armgs and legs back and forth and make gore angels!

    FDuckl!
  • Zune-Tran 2011-10-31 13:33
    geoffrey:
    Zune-Tran:
    C-Octothorpe:
    Bananas:
    In my book
    Highly unlikely...
    Why? I find it pretty easy to believe he has a book of "bananas" on his night stand. Right next to the box of tissues.
    I once had a nightstand.
    Cause I could only stand it for one night.
    HAND-stand it. That's where you put one fist in her cunt and one in her ass and then spread out your fingers and due a hand-stand. Ideally, this will make her cry and scream in pain, so that I will finally be able to get an erection.
  • doctor_of_common_sense 2011-10-31 13:33
    Zune-Tran:
    C-Octothorpe:
    Bananas:
    In my book
    Highly unlikely...
    Why? I find it pretty easy to believe he has a book of "bananas" on his night stand. Right next to the box of tissues.


    I find your lack of disbelief disturbing.
  • PedanticCurmudgeon 2011-10-31 13:41
    JL:
    Steve The Cynic:
    milleniumbug:
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!
    Nothing wrong with comments in a #define.

    ...

    Unless that #define is expanded in the middle of an expression! The latter half of the expression will be silently commented out. It might not even cause a syntax error, depending on where the next semicolon appears in subsequent lines of code.

    The effect is much like running Dissociated Press on your code.
    Congratulations, Steve, looks like you got a bite! Apparently, no troll is too obvious here.
  • Ken B. 2011-10-31 13:44
    JL:
    Steve The Cynic:
    milleniumbug:
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!
    Nothing wrong with comments in a #define.

    ...
    Unless that #define is expanded in the middle of an expression! The latter half of the expression will be silently commented out. It might not even cause a syntax error, depending on where the next semicolon appears in subsequent lines of code.

    The effect is much like running Dissociated Press on your code.
    Well, except for the fact that comments are not part of the macro.

    #define	PART1	"Hello, " 	// hello
    
    #define PART2 "world.\n" // world

    int main(void)
    {
    printf( PART1 PART2 );
    }
  • geoffrey 2011-10-31 13:52
    Ken B.:
    JL:
    Steve The Cynic:
    milleniumbug:
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!
    Nothing wrong with comments in a #define.

    ...
    Unless that #define is expanded in the middle of an expression! The latter half of the expression will be silently commented out. It might not even cause a syntax error, depending on where the next semicolon appears in subsequent lines of code.

    The effect is much like running Dissociated Press on your code.
    Well, except for the fact that comments are not part of the macro.

    #define	PART1	"Hello, " 	// hello
    
    #define PART2 "world.\n" // world

    int main(void)
    {
    printf( PART1 PART2 );
    }


    Even though macros can be part of the comments...

    // hello   #define	PART1	"Hello, "
    
    //world #define PART2 "world.\n"

    int main(void)
    {
    printf( PART1 PART2 );
    }
  • Cthulhu 2011-10-31 14:01
    Out of interest what is the benefit of using a macro in C/C++ to define a constant?

    What does it give you that a constant variable doesn't?
  • Nagesh 2011-10-31 14:08
    Matt Westwood:
    trtrwtf:
    Matt Westwood:
    geoffrey:
    trtrwtf:
    Matt Westwood:

    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.


    Style is fashion - do what everyone on your project does, it'll be okay.
    K&R is popular in books because vertical line space is expensive in print. On the screen, vertical line space is free, and if it's an issue it's an alarm bell: time to refactor.

    I prefer the One True Brace Style (Allman style) because it lets me line up the braces by eye, and makes the blocks more obvious. But whatever, in this world there are certainly bigger things to get worked up about.
    Single-line braces are a belt-and-suspenders thing, at best. If you're doing everything else right, they don't make a lot of difference, and they busy up your code. If you're doing everything else wrong, they're not likely to make a lot of difference, and they busy up your code. So don't bother, I say, just do everything else right.


    Reminds me of a job I had 15 years ago. I was moved onto a long running project and found myself on the "team" of a real bunch of K&R apologists. Despite my best attempts to educate them as to the merits of single line quotes they forced me to use K&R. Joke was on them though, each day I would secretly convert pieces of the code from K&R to single brace (as well as making some other more aesthetic and functional changes/improvements). Then when they went home each night I would disable the source control notification system, force commit my changes (ie overwrite the repository - this was long before CVS even) and renable the system again.

    Slowly but surely the whole code base was improved (from the most obscure files upwards) and by the time they realized what had happened (weeks later) it was already too late to change it back.


    What a shitty thing to do.


    What, you mean responding to a troll?


    Good call. It was a knee-jerk reaction. He's a jerk, I kneed him.


    Perheps Matt, you need him!
  • frits 2011-10-31 14:09
    Cthulhu:
    Out of interest what is the benefit of using a macro in C/C++ to define a constant?

    What does it give you that a constant variable doesn't?
    If wielded correctly, magical lasso powers.
  • airdrik 2011-10-31 14:09
    Bananas:
    Utterly Confused:
    >#define TASK_RATE_ONE_SECOND (TASK_RATE * 40)

    What would this mean, the number of TASK_RATE tasks in one second? If so, yeah, this is 200 for a TASK_RATE of 5 ms BUT it should be computed as 1000/TASK_RATE ***CONFUSED***
    Whoever created this mess fell into the all-too-common trap of using the word "rate" when he clearly meant "interval" instead. If you increase the value of that thing he named "rate" you will decrease the actual rate at which things happen.

    Does that help?


    What if it actually was a rate - after all TASK_RATE_ONE_SECOND does contain how many times the task gets fired per second when TASK_RATE is 5 milliseconds. TASK_RATE_FOUR_SECONDS similarly.
    The problem is that contrary to what the comment says TASK_RATE is not a number of seconds, it is the number of tasks that run every 25 milliseconds (it just happens to be that setting TASK_RATE to 5 leads to the task being run every 5 milliseconds).
  • @Deprecated 2011-10-31 14:12
    Cthulhu:
    Out of interest what is the benefit of using a macro in C/C++ to define a constant?

    What does it give you that a constant variable doesn't?


    Ummm, math errors?

    I once helped a guy debug his program, and essentially it came down to (paraphrased):

    // in some header
    #define EIGHT 3 + 5

    // later in another file
    printf("8 * 2 = %d\n", EIGHT * 2);

    8 * 2 = 13


  • Zapp Brannigan 2011-10-31 14:14
    Hortical:
    Bananas:
    Utterly Confused:
    >#define TASK_RATE_ONE_SECOND (TASK_RATE * 40)

    What would this mean, the number of TASK_RATE tasks in one second? If so, yeah, this is 200 for a TASK_RATE of 5 ms BUT it should be computed as 1000/TASK_RATE ***CONFUSED***
    Whoever created this mess fell into the all-too-common trap of using the word "rate" when he clearly meant "interval" instead. If you increase the value of that thing he named "rate" you will decrease the actual rate at which things happen.

    Does that help?
    Awww, man, don't even get me started - I hate fuckers! They make me want to strap them to the front of my car, go driving through head on traffic, and then stop, get out, ans as they begr for mercy, bring a cinder block down on their head! Smash their body into glop, spread it all over the ground and then lay down, move my armgs and legs back and forth and make gore angels!

    FDuckl!

    Lighten up Francis.
  • boog 2011-10-31 14:15
    frits:
    Cthulhu:
    Out of interest what is the benefit of using a macro in C/C++ to define a constant?

    What does it give you that a constant variable doesn't?
    If wielded correctly, magical lasso powers.
    Depends on the compiler; GNU variants typically give you mystical bola skills.
  • your name 2011-10-31 14:17
    I need to file a ticket to update the order of the update and the order of updateorder.
  • Anon 2011-10-31 14:19
    catdog:
    The one from Ryan is not a WTF. The method may just return now, but could easily be a hook for something that needs to be done for the future. The try/catch is probably something they require as part of a process for all of their methods...


    Yes, it is a WTF. Just not in the way Ryan pointed out. The WTF would be wrapping all your code in a try/catch all that does nothing but put some information in the message that is already in the stack trace.
  • clive 2011-10-31 14:41
    trtrwtf:
    I prefer the One True Brace Style (Allman style)


    1TBS != Allman. You probably don't like 1TBS.
  • foo 2011-10-31 14:55
    Cthulhu:
    Out of interest what is the benefit of using a macro in C/C++ to define a constant?

    What does it give you that a constant variable doesn't?

    On the odd chance this was a serious question: In C++ not much. In C, a constant variable can't be used as a case label or static array size. Though an enum (ab)used as an int can, which I usually prefer.

    (Otherwise, much is historic as early versions of C didn't have constant variables.)
  • Brian White 2011-10-31 17:26
    "In case it's not obvious from the class names," writes Veggen Skrikk, "the only difference between the beans is that one (unsuccessfully) attempts to use DB transactions and another does not. Naturally, they both operated on the same underlying database table. This was the previous guy's way to introduce experimental features into the application. Experimental features like transactions. That don't work."


    Why is using transactions 'experimental' code? And why doesn't it work? True, the function name was bad, but it is a much more serious WTF that you are updating orders without using a transaction. That will let half your order be changed and half of it fails to change and there's no way to recover.
  • gnasher729 2011-10-31 17:33
    geoffrey:
    Reminds me of a job I had 15 years ago. I was moved onto a long running project and found myself on the "team" of a real bunch of K&R apologists. Despite my best attempts to educate them as to the merits of single line quotes they forced me to use K&R. Joke was on them though, each day I would secretly convert pieces of the code from K&R to single brace (as well as making some other more aesthetic and functional changes/improvements). Then when they went home each night I would disable the source control notification system, force commit my changes (ie overwrite the repository - this was long before CVS even) and renable the system again.

    Slowly but surely the whole code base was improved (from the most obscure files upwards) and by the time they realized what had happened (weeks later) it was already too late to change it back.

    Any place I've worked in the last 25 years, someone subverting source code control like this would have been fired. Maybe too late to change it back, but not too late to get rid of the culprit.
  • Carl 2011-10-31 17:33
    Ken B.:
    ... comments are not part of the macro.
    #define	PART1	"Hello, " 	// hello
    
    #define PART2 "world.\n" // world
    int main(void)
    {
    printf( PART1 PART2 );
    }
    You should know that here, more than anywhere, you must test your code before posting it!
    $ perl 
    
    #define PART1 "Hello, " // hello
    #define PART2 "world.\n" // world

    int main(void)
    {
    printf( PART1 PART2 );
    }
    syntax error at - line 9, near ")
    {"
    Execution of - aborted due to compilation errors.
  • Matt Westwood 2011-10-31 17:52
    Nagesh:
    Matt Westwood:
    trtrwtf:
    Matt Westwood:
    geoffrey:
    trtrwtf:
    Matt Westwood:

    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.


    Style is fashion - do what everyone on your project does, it'll be okay.
    K&R is popular in books because vertical line space is expensive in print. On the screen, vertical line space is free, and if it's an issue it's an alarm bell: time to refactor.

    I prefer the One True Brace Style (Allman style) because it lets me line up the braces by eye, and makes the blocks more obvious. But whatever, in this world there are certainly bigger things to get worked up about.
    Single-line braces are a belt-and-suspenders thing, at best. If you're doing everything else right, they don't make a lot of difference, and they busy up your code. If you're doing everything else wrong, they're not likely to make a lot of difference, and they busy up your code. So don't bother, I say, just do everything else right.


    Reminds me of a job I had 15 years ago. I was moved onto a long running project and found myself on the "team" of a real bunch of K&R apologists. Despite my best attempts to educate them as to the merits of single line quotes they forced me to use K&R. Joke was on them though, each day I would secretly convert pieces of the code from K&R to single brace (as well as making some other more aesthetic and functional changes/improvements). Then when they went home each night I would disable the source control notification system, force commit my changes (ie overwrite the repository - this was long before CVS even) and renable the system again.

    Slowly but surely the whole code base was improved (from the most obscure files upwards) and by the time they realized what had happened (weeks later) it was already too late to change it back.


    What a shitty thing to do.


    What, you mean responding to a troll?


    Good call. It was a knee-jerk reaction. He's a jerk, I kneed him.


    Perheps Matt, you need him!


    Oh dear. I was really, really hoping someone wouldn't say that. (*shame*)
  • yername 2011-10-31 17:58
    Dave:
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?

    I heard Visual C++ 4 used to drop entire blocks of code.
    Must have been fun debugging that.
  • Herby 2011-10-31 18:07
    Magic can be done in many ways. Back in my Fortran days, it was common to do:

    PI + ATAN(1.0) * 4

    Always got the correct precision.

    As for comments in "#define" statements, everyone should know that comments are removed BEFORE any pre-processing is done. It is in the language specification.
  • Utterly Confused 2011-10-31 18:20
    airdrik:
    Bananas:
    Utterly Confused:
    >#define TASK_RATE_ONE_SECOND (TASK_RATE * 40)

    What would this mean, the number of TASK_RATE tasks in one second? If so, yeah, this is 200 for a TASK_RATE of 5 ms BUT it should be computed as 1000/TASK_RATE ***CONFUSED***
    Whoever created this mess fell into the all-too-common trap of using the word "rate" when he clearly meant "interval" instead. If you increase the value of that thing he named "rate" you will decrease the actual rate at which things happen.

    Does that help?


    What if it actually was a rate - after all TASK_RATE_ONE_SECOND does contain how many times the task gets fired per second when TASK_RATE is 5 milliseconds. TASK_RATE_FOUR_SECONDS similarly.
    The problem is that contrary to what the comment says TASK_RATE is not a number of seconds, it is the number of tasks that run every 25 milliseconds (it just happens to be that setting TASK_RATE to 5 leads to the task being run every 5 milliseconds).


    I see, so either the comment is correct and the math is wrong, or the math is right but the comment is wrong.
    And in both cases it just happens to give the number they want, for that given 5.

    \me bangs my head on the desk, violently.
  • Jimmy 2011-10-31 19:05
    trtrwtf:
    Matt Westwood:

    Interesting how fashions change. There's lots of bollocks being talked about single line curly braces at the moment. I think it looks shit, by the way.

    Used to be that the Egyptian style, a.k.a the K&R style, was king. Now suddenly it's not.


    Style is fashion - do what everyone on your project does, it'll be okay.
    K&R is popular in books because vertical line space is expensive in print. On the screen, vertical line space is free, and if it's an issue it's an alarm bell: time to refactor.

    I prefer the One True Brace Style (Allman style) because it lets me line up the braces by eye, and makes the blocks more obvious. But whatever, in this world there are certainly bigger things to get worked up about.
    Single-line braces are a belt-and-suspenders thing, at best. If you're doing everything else right, they don't make a lot of difference, and they busy up your code. If you're doing everything else wrong, they're not likely to make a lot of difference, and they busy up your code. So don't bother, I say, just do everything else right.
    100% agree (well over 80%, anyways). More important to be consistent with the project you are working on, than vigorously protest that everyone who has ever worked on your project is doing it wrong, and that your way is right and therefore should be followed for all future modifications.

    Agree too that Braces lining up is a nice thing - especially as code gets complex.

    If by 'single line braces' you mean surrounding a single statement (eg in an in statement) by braces, then I think in-principle we should - however I always justify not doing so. That said, if you don't use the braces, keep the statement on the same line as the "if", "else", "while", "for" or whatever to be clear...
    ie:

    /* In theory do this */
    if(something)
    {
    callMethod();
    }

    /* in practice don't do this */
    if(something)
    callMethod();

    /* and instead use */
    if(something) callMethod();

    IMO the last construct makes it clearer that the intention is for only one statement to be executed.

    That said, I tend to agree with your Belt and Suspenders bit..
  • HoHum 2011-10-31 19:26
    QJo:
    Dave:
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?


    I'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.

    The trick then is, after you *have* finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).
    Assuming you're not a troll (and it is getting hard for me to tell, maybe I been hanging around here too much) even in such a case, wouldn't you then investigate why?

    Restoring the expected behaviour is nice, but unless you understand WHY something that doesn't seem to make sense makes things good then how do you know you've fixed the problem?

    Example:
    Someone I worked with was debugging code that equated to something like this:

    char *getString()
    {
    char myString[15];
    strncpy(myString, "Hello There\n", 12);
    return myString;
    }

    int main(void)
    {
    char *temp;
    temp = getString();
    printf("%s", temp);
    printf("%s", temp);
    doSomething(temp);
    }

    They were puzzled as to why both print statements had different behaviour (from memory, the first worked, and the second caused the program to die). The obvious fix (which might appear to work) is not to call either, but the real issue is to work out why temp is getting clobbered (for the non-C programmer: the reference returned from getString is on the stack, and is only in scope for the getString method. Although the memory appears valid, and can still be accessed, any function call will expand the stack, and risks clobbering the data at this location (and in this case, printf did - although I can't seem to replicate the issue now).

    Using the obvious fix, we might seem to get the right behaviour by using the variable without calling anything else, but suppose later someone adds a function call in between?

    Point is, by all means try things that seem non-intuitive to fix issues, but be certain you understand why your fix works (if it does), before deciding to deploy the change...
  • HoHum 2011-10-31 19:26
    Bananas:
    QJo:
    Dave:
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?


    I'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.

    The trick then is, after you *have* finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).
    Hrmmm.... troll or slacker?

    Yeah, sometimes just trying stuff at random is the only option left. But once you've found a random something that makes stuff work better, then you use that as a clue to resume your search for the real cause of the problem.

    In my book you haven't really fixed the problem until you can explain exactly why your change made things get better, and you have included that explanation as a comment in the code, rather than your whiny simpering complaint about lost hours.


    Retract my last.....what "Banana" said....
  • bligwad 2011-10-31 19:28
    JL:
    Steve The Cynic:
    milleniumbug:
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!

    Nothing wrong with comments in a #define.

    ...



    Unless that #define is expanded in the middle of an expression! The latter half of the expression will be silently commented out. It might not even cause a syntax error, depending on where the next semicolon appears in subsequent lines of code.

    The effect is much like running Dissociated Press on your code.
    Not something I've come across...

    MinGW definitely is ok with comments after defines, pretty sure gcc is too....
  • Jiuyta 2011-10-31 19:29
    Jay:
    Bananas:
    QJo:

    I'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.

    The trick then is, after you *have* finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).
    Hrmmm.... troll or slacker?

    Yeah, sometimes just trying stuff at random is the only option left. But once you've found a random something that makes stuff work better, then you use that as a clue to resume your search for the real cause of the problem.

    In my book you haven't really fixed the problem until you can explain exactly why your change made things get better, and you have included that explanation as a comment in the code, rather than your whiny simpering complaint about lost hours.


    But sometimes you never do figure it out. I'm not saying that's a desirable state, but that's how it is.

    The next worse thing after "It doesn't work and I have no idea why not" is "It does work and I have no idea why."
    Never deploy if you don't know why. If you can't explain it, how do you know it actually works?
  • Jiuyta 2011-10-31 19:36
    foo:
    Cthulhu:
    Out of interest what is the benefit of using a macro in C/C++ to define a constant?

    What does it give you that a constant variable doesn't?

    On the odd chance this was a serious question: In C++ not much. In C, a constant variable can't be used as a case label or static array size. Though an enum (ab)used as an int can, which I usually prefer.

    (Otherwise, much is historic as early versions of C didn't have constant variables.)

    1) C didn't have constants, but constants are good - of course, you could simply define a global variable, but it could get modified.
    2) Can't dereference a macro and change it
  • HP PhaserJet 2011-10-31 20:41
    Tell me, this, Westwood: just how, accepting, of Eddie Murphy are the, British? I'm really, really, curious to? know?

    But, could I ever get, an honest answer?

    Did you, or did you not, enjoy the family, farting scene from, The Nutty Professor?

    Are you a racist?! Does your hatred, for Asians, run so deep, that you would, cast such blatant, !ludicrous!? "No" you say, but can you be honest, even with yourself?

    Have you ever been?
    Honest?
    With, yourself?

    Maybe you're just, afraid to be?
  • +9 2011-11-01 04:05
    I've been told it's very hard to get a good programming job... Wtf?
  • Severity One 2011-11-01 04:36
    The Mr. T Experience:
    Severity One:
    The Mr. T Experience:
    TRWTF is listing "French" and "Gay" separately.
    You are obviously unfamiliar with Alizée.
    Do you mean the singer? Why? because you think she's hot? I suppose you also think that Harry potter movies aren't gay because you have a crush on that little girl Emma what's-her-name?
    Watson. In the first film, she was a child. Right about now, I'd say she's hot, yes. Still over 20 years my junior, though.

    Hey, if my wife can look at Alexander Skarsgård, him with a disturbing lack of upper-body clothing and then declare that nobody is as good looking as I am, I think I'm entitled to ogle Emma Watson and tell my wife she's the most beautiful woman in the world.
  • itsmo 2011-11-01 04:54
    geoffrey:
    Zune-Tran:
    C-Octothorpe:
    Bananas:
    In my book
    Highly unlikely...
    Why? I find it pretty easy to believe he has a book of "bananas" on his night stand. Right next to the box of tissues.


    I once had a nightstand and let me tell you, it's no laughing matter.


    FTFY
  • itsmo 2011-11-01 04:57
    HP PhaserJet:
    Tell me, this, Westwood: just how, accepting, of Eddie Murphy are the, British? I'm really, really, curious to? know?

    But, could I ever get, an honest answer?

    Did you, or did you not, enjoy the family, farting scene from, The Nutty Professor?

    Are you a racist?! Does your hatred, for Asians, run so deep, that you would, cast such blatant, !ludicrous!? "No" you say, but can you be honest, even with yourself?

    Have you ever been?
    Honest?
    With, yourself?

    Maybe you're just, afraid to be?


    You're punctuation is nutty...
  • QJo 2011-11-01 05:31
    HoHum:
    Bananas:
    QJo:
    Dave:
            if (obj == null)
    
    {
    return "";
    }
    if ((obj == null))
    {
    return "";
    }
    Clearly this guy is one of those who thought "something isn't working; let me try this". For some reason the technology world (and maybe the rest of the world?) is full of "try this" people who never bother to figure out what's actually wrong. You'll find them on every helpless desk: Did you try rebooting?

    If you're a "try this" guy, I have only one thing to say to you: Did you try thinking?


    I'm not suggesting that this was one of those moments, but sometimes there just is no other option than to try stuff at random until stuff just works.

    The trick then is, after you *have* finally got it working and you've wiped away your tears and blown your nose, to remove all the shrapnel and shards, applying the appropriate metaphorical superglue to tidy it up again as though it had never been a problem. (Oh, and it might be nice if you put a comment in place explaining why your afternoon, evening, night and wee small hours have been so generally unproductive).
    Hrmmm.... troll or slacker?

    Yeah, sometimes just trying stuff at random is the only option left. But once you've found a random something that makes stuff work better, then you use that as a clue to resume your search for the real cause of the problem.

    In my book you haven't really fixed the problem until you can explain exactly why your change made things get better, and you have included that explanation as a comment in the code, rather than your whiny simpering complaint about lost hours.


    Retract my last.....what "Banana" said....


    The implication in my original reply was that when you *have* finally got it working you *do* understand what the problem actually was. Otherwise how would you *know* you'd got it working? That's what I meant about updating the comments. Is that what you've always done, Bananas and HoHum? Or are your postings the result of guilty memories you yourselves have of leaving something that appeared to be fixed but was in fact even more broken than it was before you started mucking about with it?
  • no laughing matter 2011-11-01 07:19
    itsmo:
    geoffrey:

    I once had a nightstand and let me tell you, it's no laughing matter.


    FTFY

    How comes i had overlooked that?

    geoffrey, next time when you want to swallow the blue pill, please inform me first!
  • Triscopic 2011-11-01 07:51
    yername:

    I heard Visual C++ 4 used to drop entire blocks of code.
    Must have been fun debugging that.


    For a while Qt's IDE would randomly delete collapsed blocks of code when files were saved. That was tonnes of fun.
  • no laughing matter 2011-11-01 08:09
    Triscopic:
    yername:

    I heard Visual C++ 4 used to drop entire blocks of code.
    Must have been fun debugging that.


    For a while Qt's IDE would randomly delete collapsed blocks of code when files were saved. That was tonnes of fun.

    No, it was me!
  • Nix Nada 2011-11-01 08:28
    I tried to learn to speak Gay but I couldn't get my tongue around the hard bits.
  • PedanticCurmudgeon 2011-11-01 08:58
    HoHum:
    Assuming you're not a troll (and it is getting hard for me to tell...
    Look, it's quite simple:

    1. Is the post a heated response to a post that is either ill-informed or just plain stupid? If so, they have been trolled.

    2. Is the post lofty pontification about something nobody really cares about? If so, it may be annoying, but not a troll.

    3. If the post doesn't fall under either of the above categories, it's a troll.
  • milleniumbug 2011-11-01 10:49
    Steve The Cynic:
    milleniumbug:
    #define TASK_RATE (5) //Task rate in milliseconds

    WTF? Comments in define!

    Nothing wrong with comments in a #define.

    However, in the real world, "rates" are measured in Hz, not seconds. It should be TASK_INTERVAL or TASK_PERIOD or something like that.

    Well, assuming it really is in milliseconds, that is, and not work-units per unit of time.


    Yeah, I just realized that the comments are left alone by the preprocessor - good to know.
  • TheSHEEEP 2011-11-01 11:09
    http://code.google.com/p/ofxtools/source/browse/trunk/OfxCommon/simpleOFX.cs?r=7

    A quick google for one of the long strings came up with that o.o
  • QJo 2011-11-01 11:46
    TheSHEEEP:
    http://code.google.com/p/ofxtools/source/browse/trunk/OfxCommon/simpleOFX.cs?r=7

    A quick google for one of the long strings came up with that o.o


    Goodness so it was:

    // This code was generated by a tool.


    The comment must have been put in place by the maintainer, who clearly has issues with the programming style of his predecessor.
  • Matt Westwood 2011-11-01 15:51
    HP PhaserJet:
    Tell me, this, Westwood: just how, accepting, of Eddie Murphy are the, British? I'm really, really, curious to? know?

    But, could I ever get, an honest answer?

    Did you, or did you not, enjoy the family, farting scene from, The Nutty Professor?

    Are you a racist?! Does your hatred, for Asians, run so deep, that you would, cast such blatant, !ludicrous!? "No" you say, but can you be honest, even with yourself?

    Have you ever been?
    Honest?
    With, yourself?

    Maybe you're just, afraid to be?


    Eddie Murphy? Bag of shite.

    Nutty Professor: I have managed to avoid having seen it, and I'm going to make sure it stays that way. There is only one fart joke in movies worth a fuck and that's in Blazing Saddles.

    And when did I ever express hatred for Asians?

    Now don't do drugs and WTF at the same time again, or you'll make yourself look even more fucking stupid than you already have.
  • Kuron 2011-11-01 18:33
    After reading the comment, maybe he wanted the Logoff to be a success, and made it return true ;)
  • Dirk 2011-11-01 19:01
    "Error in ManageRelations method of Biz Rules media of HE"
    Great! Because you never can trust the stack trace.
  • Fag 2011-11-01 19:22
    I can't believe we haven't set off an anti-homophobic rant. I'm impressed guys!
  • yername 2011-11-01 19:25
    Triscopic:
    yername:

    I heard Visual C++ 4 used to drop entire blocks of code.
    Must have been fun debugging that.


    For a while Qt's IDE would randomly delete collapsed blocks of code when files were saved. That was tonnes of fun.

    Just to clarify: I meant the compiler and not the IDE.
  • Chris 2011-11-01 23:51
    Matt Westwood:

    writtenComment() {
    return true;
    }


    it's not really a WTF. If the codebase makes use of callbacks / anonymous functions, then it is perfectly valid to have functions simply return true.

    And it's also not new. The same "WTF" gets posted on a regular basis.
  • bobthecoder 2011-11-02 06:16
    I once admonished a programmer for using an exceptionally short and meaningless method name. He never took this criticism well and blatantly had an attitude problem because the next thing I saw was something like:

    method get_user_id_and_load_user_and_check_date_and_if_old_perform_action(integer id_of_user);
  • QJo 2011-11-02 06:58
    bobthecoder:
    I once admonished a programmer for using an exceptionally short and meaningless method name. He never took this criticism well and blatantly had an attitude problem because the next thing I saw was something like:

    method get_user_id_and_load_user_and_check_date_and_if_old_perform_action(integer id_of_user);


    Don't tell me: you had a fist-fight with him in the office, where it spilled out into the corridor and into the car park?
  • no laughing matter 2011-11-02 08:30
    bobthecoder:
    method get_user_id_and_load_user_and_check_date_and_if_old_perform_action(integer id_of_user);


    Loads of TRWTF:
    * Method Parameter is specified as integer, but no return type of method given: A WTF-hybrid of a statically and dynamically typed language?
    * First part of described action: get_user_id. Parameter specified: id_of_user!
    * Much too much actions for a single method. One Method, one responsibility!
    * load_user? I sense a FILE_NOT_FOUND here.
    * check_date? Which date? This risks to turn into a meme!
    * check_date_and_if_old_perform_action: BANG! Were in Zunesis-land now!

    At least bobthecoder does not claim that i am his son.

    He also is not my uncle and this is no laughing matter!
  • method1 2011-11-05 13:56
    Steve The Pirate:
    That is an interesting value to initialize your int to

    Now why don't compilers have sarcastic error messages like this. It could be a compiler switch.
  • C 2011-11-08 05:13
    Steve The Pirate:
    C-Octothorpe:
    That last one is eerily similar to the code-base I inherited about a year ago, except replace all the "safe" if blocks with try/catch blocks...
    public static int StringToInt32(string str)
    
    {
    try {
    return int.parse(str);
    }
    catch { return 0; }
    }
    Ahh, now that's a beaute! Or the single return variant:
    public static int StringToInt32(string str)
    
    {
    int returnValue = "";

    try {
    returnValue = int.parse(str);
    }
    catch { }

    return returnValue;
    }
    Now if this "pattern" doesn't scream "I don't give a shit about the quality of my code", then I don't know what does...

    That is an interesting value to initialize your int to
    Don't you mean "initialize your itn" instead?! RTFC!
  • Tero Tilus 2011-11-08 15:01
    Who ever came up with the naming conventions used in OFX schema deserves a bare bottom spanking.
  • wow 2011-11-13 22:25
    That last one really got me.
  • anonymous 2013-06-13 15:53
    public override EngineBlockCasting Inspect(Casting)
    
    {
    if (Casting.IsGood) {
    try
    {
    return Casting;
    }
    catch (Exception BrokenConveyer)
    {
    throw Casting;
    }
    }
    }

    Bonus points if anybody can make it calculate the ballistics on a PostScript printer.