• (cs) in reply to Dave
    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).

  • (cs) in reply to Severity One
    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 (unregistered) in reply to QJo
    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.

  • (cs) in reply to Bananas
    Bananas:
    In my book
    Highly unlikely...
  • Jay (unregistered) in reply to Dave
    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 (unregistered) in reply to Steve The Cynic
    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 (unregistered) in reply to Bananas
    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 (unregistered) in reply to QJo
    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 (unregistered) in reply to C-Octothorpe
    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 (unregistered) in reply to Zune-Tran
    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. (unregistered) in reply to Alex
    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 (unregistered) in reply to Bananas
    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 (unregistered) in reply to geoffrey
    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 (unregistered) in reply to Zune-Tran
    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.

  • (cs) in reply to JL
    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. (unregistered) in reply to JL
    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 (unregistered) in reply to Ken B.
    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 );
    	}
  • (cs)

    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?

  • (cs) in reply to Matt Westwood
    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!

  • (cs) in reply to Cthulhu
    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 (unregistered) in reply to Bananas
    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).

  • (cs) in reply to Cthulhu
    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 (unregistered) in reply to Hortical
    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.

  • (cs) in reply to frits
    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 (unregistered)

    I need to file a ticket to update the order of the update and the order of updateorder.

  • Anon (unregistered) in reply to catdog
    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 (unregistered) in reply to trtrwtf
    trtrwtf:
    I prefer the One True Brace Style (Allman style)

    1TBS != Allman. You probably don't like 1TBS.

  • foo (unregistered) in reply to Cthulhu
    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 (unregistered)
    "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 (unregistered) in reply to geoffrey
    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 (unregistered) in reply to Ken B.
    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.

  • (cs) in reply to Nagesh
    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 (unregistered) in reply to Dave
    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 (unregistered)

    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 (unregistered) in reply to airdrik
    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 (unregistered) in reply to trtrwtf
    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 (unregistered) in reply to QJo
    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 (unregistered) in reply to Bananas
    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 (unregistered) in reply to JL
    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 (unregistered) in reply to Jay
    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 (unregistered) in reply to foo
    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 (unregistered) in reply to Matt Westwood

    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 (unregistered)

    I've been told it's very hard to get a good programming job... Wtf?

  • (cs) in reply to The Mr. T Experience
    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 (unregistered) in reply to geoffrey
    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 (unregistered) in reply to HP PhaserJet
    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...

  • (cs) in reply to HoHum
    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?

  • (cs) in reply to itsmo
    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 (unregistered) in reply to yername
    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.

  • (cs) in reply to Triscopic
    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!

Leave a comment on “Useless Functions, Extreme Naming, and More”

Log In or post as a guest

Replying to comment #:

« Return to Article