• IDK (unregistered) in reply to awt
    awt:
    I'm just surprised the coder was content with:

    if ( confirm(msg) ) rather than if ( confirm(msg) == true )

    Though I suppose that might have given him a hint about the easier way to do it..

    x==true <!=> x becouse x <=> (x>0) && (true==1)

    which gives x==1 <!=> x>0

    captcha: craaazy, yepp that's me

  • tieTYT (unregistered) in reply to JOHN
    JOHN:
    Not a WTF.

    I've seen this hundreds of times in two different cases:

    1. confirmMessage used to have more logic but was refactored out, however the code calling this function is too numerous to refactor as well.

    2. confirmMessage will eventually become more complex, but confirm is used in other places that don't need the future logic, so this placeholder is created so that other modules can begin to use the function even though it is not complete yet.

    Therefore, not a WTF.

    the if statement is still a little whacky. But this is the type of shit that i think everyone does once in a while. It doesn't make me say, ZOMG what a l00z3r

  • BTX (unregistered)

    ah! I get it, they forgot to return "Not Found"!

  • GrandmasterB (unregistered)

    The correct way of doing this function is:

    function confirmMessage(msg) 
    { 
       return confirm( "I WANT BEAN BAG GIRL"); 
    } 
    

    Really, though, there's too many possible scenarios for this functio to come about (used to be more logic, planning on adding more, planning on switching to DHTM confirms, etc) for this to be a real code wtf to anyone who's actually programmed in the real world.

  • (cs) in reply to JTK
    JTK:
    Kuba:
    Because greap+sed or awk, and the two or three lines of bash to do all this (checkout the files, change, commit) is just so damn hard you know.

    Oh, you say you do this development on Windows? Too bad.

    Cheers!

    You obviously work on a small team without a dedicated test group. On a large project, to make such a sweeping change requires one to:

    1. Wait for all 200 files to become unlocked so you can check them out.

    2. Make the change.

    3. Unit test every single method that you just touched.

    4. Check in each of 200 files, with appropriate release notes and defect references.

    5. Listen to the test team gripe because they now have to regression test each feature that you just altered.

    6. Endure the criticism of your manager because you just threw the project off schedule.

    It's much easier to make the change in one spot, and the compiler will probably optimize it away anyway.

    Ok, I was going to reply the previous poster until I saw you. LOL

    1) Wait for all 200 files to become unlocked so you can check them out.

    So you are developing in Windows after all... Too bad for you. All your steps shouldn't be that hard for a simple refactoring. Number 5 and 6 are the worse ones, that should save time on the long term, unless you are refactoring code at the release week...

    Now, seriously, one can't trust sed to edit code. That will create much bigger WTFs than just keeping it there. But grep is your friend.

  • (cs) in reply to JTK
    JTK:
    Kuba:
    webhamster:
    W:
    Aye, this is just a way to abstract away message displaying. This way it's easy to change how a confirm dialog is displayed (be it the normal confirm() box, or some popup or similar (not that that wouldn't be a WTF)) without altering all the code that uses confirmation dialogs.

    Exactly. If it's a method used in 200 places it's easier to make a change once than to make it 200 times through the whole codebase.

    Because greap+sed or awk, and the two or three lines of bash to do all this (checkout the files, change, commit) is just so damn hard you know.

    Oh, you say you do this development on Windows? Too bad.

    Cheers!

    You obviously work on a small team without a dedicated test group. On a large project, to make such a sweeping change requires one to:

    1. Wait for all 200 files to become unlocked so you can check them out.

    2. Make the change.

    3. Unit test every single method that you just touched.

    4. Check in each of 200 files, with appropriate release notes and defect references.

    5. Listen to the test team gripe because they now have to regression test each feature that you just altered.

    6. Endure the criticism of your manager because you just threw the project off schedule.

    It's much easier to make the change in one spot, and the compiler will probably optimize it away anyway.

    If I'm changing an API that gets used by every feature, it's generally a best practice for the test team to regression test everything anyhow. Suppose some guy changes this to a DHTML confirm box that relies on a particular DOM element that's only present in 95% of the pages...

    "But testing every page for every change is a pain", the testers say. Well, is testing in this case is just as necessary as it is if I replaced all those references to confirm(). So if you're comfortable doing less testing in this case, why not slack off in the other case too? I mean, it's not like testing is part of your job description or anything.

    / I have had to deal with the pain of checking out all those files myself, and it can be a pain

  • fanha (unregistered)

    The real WTF is the comments. This isn't a WTF at all, it's an adaptor, a (trivially) light wrapper for platform independence, a reduced function left in for compatibility, or a debugging tool. The fact that many people think this is a WTF is the cause of many more WTFs regarding bad encapsulation and abstraction.

    A wrapper like this often eliminates redundancy later in development, so calling it a WTF for being redundant shows a fundamental misunderstanding of what redundancy in code means, and a failure to understand the value of abstraction and flow control. I would go so far as to say it's quite likely that the person programming this follows better practices than the people commenting here.

  • Buckaroo Bonzai (unregistered) in reply to Christian
    Christian:
    I have seen such stuff also very often.

    Signed, Strongbad.

  • incoherent (unregistered) in reply to fanha
    fanha:
    The real WTF is the comments. This isn't a WTF at all, it's an adaptor, a (trivially) light wrapper for platform independence, a reduced function left in for compatibility, or a debugging tool. The fact that many people think this is a WTF is the cause of many more WTFs regarding bad encapsulation and abstraction.
    There's still no reason to put the if-then-else around it. If all you're going to do is return true if confirm(...) returns true and false if confirm(...) returns false, return confirm(...) works just as well.

    While I can certainly understand the single point of control argument being made here if you plan on doing something fancier, until you ARE doing something fancier there's no sense in being wordy.

  • Nerigazh (unregistered) in reply to brazzy
    brazzy:
    The horrible truth is that pointless, obfuscating layers of abstraction are common as dirt in any large OO codebase.

    There are multiple reasons: laziness or fear of refactoring, incomplete understanding of OO design, or (probably the worst) a fresh love affair with the GoF book (a phase that many programmers seem to go through).

    OK, I give up... what is the "GoF book"?

  • Shortiiik (unregistered) in reply to JOHN
    JOHN:
    Not a WTF. I've seen this hundreds of times in two different cases:
    1. confirmMessage used to have more logic but was refactored out, however the code calling this function is too numerous to refactor as well.

    2. confirmMessage will eventually become more complex, but confirm is used in other places that don't need the future logic, so this placeholder is created so that other modules can begin to use the function even though it is not complete yet.

    Therefore, not a WTF.

    I must agree.. not a WTF. I was about to write exactly the same.

  • Your Name (unregistered) in reply to fanha

    [quote user="fanha"]The real WTF is the comments. This isn't a WTF at all, it's an adaptor, a (trivially) light wrapper for platform independence, a reduced function left in for compatibility, or a debugging tool. The fact that many people think this is a WTF is the cause of many more WTFs regarding bad encapsulation and abstraction.

    [quote user="fanha"]The real WTF is the comments. This isn't a WTF at all, it's an adaptor, a (trivially) light wrapper for platform independence, a reduced function left in for compatibility, or a debugging tool. The fact that many people think this is a WTF is the cause of many more WTFs regarding bad encapsulation and abstraction.[/quote]

    It's Javascript.

    There is no platform independence benefit, as if you happened to port it to some environment other than a browser, you could just call your confirm() replacement "confirm" instead of "confirmMessage". Chances are it'll never be ported to a different platform though, as different scripting hosts are far too different for that to be practical.

    If it used to do something and no longer does, it should have been replaced with "confirmMessage = confirm". Anything else forces any future maintainers to wonder why there is a wrapper.

    If this was done for debugging purposes, the maintainer is terrible at debugging.

  • Sgt. Preston (unregistered) in reply to GrandmasterB
    GrandmasterB:
    The correct way of doing this function is:
    function confirmMessage(msg) 
    { 
       return confirm( "I WANT BEAN BAG GIRL"); 
    } 
    

    Really, though, there's too many possible scenarios for this functio to come about (used to be more logic, planning on adding more, planning on switching to DHTM confirms, etc) for this to be a real code wtf to anyone who's actually programmed in the real world.

    GrandmasterB, the "I WANT BEAN BAG GIRL" allusion left me in the dust. Can you point me in the direction of its antecedent?
  • daBowmore (unregistered) in reply to JOHN
    JOHN:
    1) confirmMessage used to have more logic but was refactored out, however the code calling this function is too numerous to refactor as well.
    And I guess you use notepad for the "refactoring"?
  • Harrow (unregistered) in reply to Kuba
    Kuba:
    Pingmaster:
    No, I agree with the theory that this is a refactor done by a twit. It does make sense to keep this function in place if it was called elsewhere in the app, trying to find every reference is a PITA and likely to break something.

    Why, oh why oh why... /me weeps.

    What horrible experience you must have in order not to be able to grep the codebase and find all the references to a particular function. Yes, I agree that running the stack of your Fortran punched cards through the system in order to grep for things was expensive, but ya know we've made some progress since then...

    Cheers!

    ...to punched paper tape...

    -Harrow.

  • (cs) in reply to Sgt. Preston
    Sgt. Preston:
    GrandmasterB, the "I WANT BEAN BAG GIRL" allusion left me in the dust. Can you point me in the direction of its antecedent?

    You are looking at the site that this comes from originally. There were ads up at one time, one for bean bags and one for something else. Each had girls on them, both good looking but in different ways. Theres was no end to the Beanbag-girl/Foozball-girl comments. I think Beanbag-girl won though.

  • JOHN (unregistered) in reply to daBowmore
    daBowmore:
    JOHN:
    1) confirmMessage used to have more logic but was refactored out, however the code calling this function is too numerous to refactor as well.
    And I guess you use notepad for the "refactoring"?

    How witty. And uninformed.

    In a large company, there are these things called "departments", where each one is responsible for a module of code. Many times these "departments" build code on top of other modules created by other departments.

    In a properly secured and audited system, one department would never have access to other departments code. Changing the interface of the code would require

    A) communicating with every department that relies on the code to tell them about the change B) Being asked by every department how the interface change would impact their code, formalize the findings and publish it company-wide for a review process. C) Wait for the review to be completed D) Make your changes in your module E) Wait for every other department to make their changes as well F) Check in the code, unit and regression test everything that changed.

    In a proper engineering environment, you can't just grep/awk whatever the hell you want, there's a chain of command and engineering principles you have to adhere to. UNIX/Loonix-type hackers always fail in engineering environments because they think writing software is as simple as writing a script to auto-change everything across an entire project. They fail to understand why 90% of the time, their cute little hacks break the system and cause havoc for everyone.

  • w00t (unregistered) in reply to Nerigazh
    Nerigazh:
    brazzy:
    The horrible truth is that pointless, obfuscating layers of abstraction are common as dirt in any large OO codebase.

    There are multiple reasons: laziness or fear of refactoring, incomplete understanding of OO design, or (probably the worst) a fresh love affair with the GoF book (a phase that many programmers seem to go through).

    OK, I give up... what is the "GoF book"?

    harry potter and the Goblet of Fire, obviously

  • (cs) in reply to Nerigazh
    Nerigazh:
    OK, I give up... what is the "GoF book"?

    ... you're serious? The "GoF Book" is Design Patterns by Gamma, Helm, Vlissides (sp?) and the other guy who's name escapes me. The Gang of Four. The de facto standard book when it comes to software design patterns. You aren't Paula, by any chance, are you?

  • Anon (unregistered) in reply to Kuba
    Kuba:
    Why, oh why oh why... /me weeps.

    What horrible experience you must have in order not to be able to grep the codebase and find all the references to a particular function. Yes, I agree that running the stack of your Fortran punched cards through the system in order to grep for things was expensive, but ya know we've made some progress since then...

    Cheers!

    You try to replace newFoo with oldFoo but someone else has a function called newFooDouble. Some comments accidentally call it newfoo. Some text containing newFoo in an unrelated context is also outputted by another part of the code. Two files redefine newFoo locally to be a different function, defined inside that code and it's acting as a class (this is javascript). Two other files have an unrelated function called newFoo and don't actually even have access to your newFoo.

    Your Name :
    It's Javascript.

    There is no platform independence benefit, as if you happened to port it to some environment other than a browser, you could just call your confirm() replacement "confirm" instead of "confirmMessage". Chances are it'll never be ported to a different platform though, as different scripting hosts are far too different for that to be practical.

    Different browsers do things differently, unfortunately.

  • Franz Kafka (unregistered) in reply to Frost
    Frost:

    Right, because we all know greap[sic]+sed, awk, and bash aren't available on Windows.

    um, yes they are.

  • Anon (unregistered)

    Also I'm sure they'll be lots of nice complaints when you change code that other have checked out and are working on themselves. Especially if one of them added another reference to newFoo in their checked out code.

    Oh right, also don't forget having to tell everyoen to now use oldFoo again instead of newFoo. Some may forget and then they'll wonder why it doesn't work for a while. Then they'll complain to your boss.

  • Your Name (unregistered) in reply to Anon
    Anon:
    Your Name :
    It's Javascript.

    There is no platform independence benefit, as if you happened to port it to some environment other than a browser, you could just call your confirm() replacement "confirm" instead of "confirmMessage". Chances are it'll never be ported to a different platform though, as different scripting hosts are far too different for that to be practical.

    Different browsers do things differently, unfortunately.

    What browser has bugs related to confirm?

  • (cs)

    That's nothing, I'm currently working on a program where the original programmer apparently did not know that relational operators return a boolean result, so there's several pages of stuff like:

    if( ShowIndex && ! HideShow ) ShowIt = TRUE; else ShowIt = FALSE;

  • Jon (unregistered) in reply to TheRubyWarlock
    TheRubyWarlock:
    ... you're serious? The "GoF Book" is Design Patterns by Gamma, Helm, Vlissides (sp?) and the other guy who's name escapes me. The Gang of Four. The de facto standard book when it comes to software design patterns. You aren't Paula, by any chance, are you?
    Only Paula would call it something incoherent like "GoF Book" when everyone recognises "Design Patterns".
  • Nicholas Sherlock (unregistered) in reply to Franz Kafka
    Franz Kafka:
    Frost:

    Right, because we all know greap[sic]+sed, awk, and bash aren't available on Windows.

    um, yes they are.

    You might want someone to take a look at your sarcasm detector.

  • BillyBob (unregistered)

    Oh boy! CodeSOD, haven't seen one of these in an eternity...

    well damn

  • Sharkie (unregistered)

    I don't think this snippet is funny.

    It's obviously from a practical and wise programmer that is trying to future-proof their Java code for the impending tri-state booleans sure to propagate into popular programming languages any day now.

  • (cs) in reply to Jon
    Jon:
    TheRubyWarlock:
    ... you're serious? The "GoF Book" is Design Patterns by Gamma, Helm, Vlissides (sp?) and the other guy who's name escapes me. The Gang of Four. The de facto standard book when it comes to software design patterns. You aren't Paula, by any chance, are you?
    Only Paula would call it something incoherent like "GoF Book" when everyone recognises "Design Patterns".

    Paula would have written "GoF Bok"

  • Old Wolf (unregistered) in reply to awt
    awt:
    I'm just surprised the coder was content with: if ( confirm(msg) ) rather than if ( confirm(msg) == true )
    Once he has mastered that, he can move on to the Expert Form: if ( (confirm(msg) == true) == true )

    Note, there is a Guru Form but I can't reveal what it is because then everybody would use it.

  • Stefan W. (unregistered)

    Old wolf has it right - you shouldn't easily believe in true; allways doublecheck whether true == true.

    But if done so, you may return (confirm (msg)) if it is true, because it's true, and - surprise, may return confirm (msg) if it's false, because it's false:

    function confirmMessage (msg) { if (confirm (msg) == true) == true) return confirm (msg); else return confirm (msg); }


    The above statement is true.

  • Immibis (unregistered) in reply to Stefan W.
    Stefan W.:
    Old wolf has it right - you shouldn't easily believe in true; allways doublecheck whether true == true.

    But if done so, you may return (confirm (msg)) if it is true, because it's true, and - surprise, may return confirm (msg) if it's false, because it's false:

    function confirmMessage (msg) { if (confirm (msg) == true) == true) return confirm (msg); else return confirm (msg); }


    The above statement is true.

    The brackets aren't matched.

    function confirmMessage (msg) { if ((confirm (msg) == true) == true) return confirm (msg); else return confirm (msg); }

    That asks the user twice. And is that really sure enough?

    function confirmMessage (msg) { if ((confirm (msg) == true) == true || (confirm(msg) != false) == (true != false)) return confirm (msg); else return confirm (msg); }

    Which will return true if confirm(msg) returns true or true, if false isn't equal to true, otherwise it will return true if confirm(msg) returns true or false.

    Even better:

    function confirmMessage(msg) { if(confirm(msg)==true || confirm(msg)==false || (confirm(msg)!=true && confirm(msg)!=false)) return confirm(msg); return maybe; }

    (yep, that will ask the user up to 3 times!)

    Captcha: kungfu (what someone should use on the author of this code before they mess up something important)

  • Immibis (unregistered) in reply to Immibis

    Oops, I just realised how long that post was!

  • Immibis (unregistered) in reply to Immibis

    Oops, I just realised how long that post was!

  • Josh (unregistered) in reply to ydant
    ydant:
    Random832:
    however, it is a little-known fact that it is IMPOSSIBLE to do a 'fancy confirm box' - the only functions that can block execution in javascript are alert, confirm, and prompt.

    It's not impossible to achieve that effect, though. You can block off the entire page by positioning certain elements over the entire window, and then pop up your HTML based dialog box in the middle. And maybe your confirm dialog doesn't need to be modal?

    Except for the fact that the function needs to return a boolean value. You could display a non-modal popup, but without any kind of callback it is pointless. The desired effect can be achieved, however.

    //In IE: 
    window.showModalDialog([params])
    
    //In Firefox: 
    var dialogWindow = window.open([params]);
    while (!dialogWindow.closed)
    {
        java.lang.Thread.sleep(200);
        dialogWindow.focus();
    }
    

    Yes, this does actually work, and I have actually deployed it. I'm sorry.

  • nick chan (unregistered) in reply to Why not?

    i'd use return confirm('message') too

    a lot of degree holders don't even know how to use

    var x = condition

    that;s why u'll see lots of

    if(x>y) return true else return false

    instead of return x>y

  • (cs) in reply to Old Wolf
    Note, there is a Guru Form but I can't reveal what it is because then everybody would use it.

    Do you mean

    return ((confirm(msg) == true) == true ) ? ( (confirm(msg) == true) == true ) : ( (confirm(msg) == true) == false );

    perhaps?

  • Samuel Carlsson (unregistered)

    I see this all the time, and even worse stuff. People just do not know their boolean logics.

  • Iceman (unregistered) in reply to Frost
    Frost:
    Kuba:
    webhamster:
    W:
    Aye, this is just a way to abstract away message displaying. This way it's easy to change how a confirm dialog is displayed (be it the normal confirm() box, or some popup or similar (not that that wouldn't be a WTF)) without altering all the code that uses confirmation dialogs.

    Exactly. If it's a method used in 200 places it's easier to make a change once than to make it 200 times through the whole codebase.

    Because greap+sed or awk, and the two or three lines of bash to do all this (checkout the files, change, commit) is just so damn hard you know.

    Oh, you say you do this development on Windows? Too bad.

    Cheers!

    Right, because we all know greap[sic]+sed, awk, and bash aren't available on Windows.

    And don't forget the Sourcesafe command line options cannot be used is scripts for performing check-outs and check-ins :-) http://msdn2.microsoft.com/en-us/library/asxkfzy4(VS.80).aspx

  • (cs) in reply to Immibis
    Immibis:
    Oops, I just realised how long that post was!
    So you decided to double-post to compensate.
  • PinkFloyd43 (unregistered)

    Who gives a crap if it works, so it's not perfect, it's not the code you would write, but I bet there are other bigger WTF's in the codebase that should be looked at!

  • FIA (unregistered) in reply to Samuel Carlsson
    Samuel Carlsson:
    I see this all the time, and even worse stuff. People just do not know their boolean logics.

    I blame Shakespeare, "To be or not to be?", it's just TRUE damnit!

  • jpd (unregistered) in reply to JTK

    Now, the "greap[sp]+sed or awk" guy is either joking, or spends his days whipping up inconsequential perl scripts in his basement. But..

    JTK:
    You obviously work on a small team without a dedicated test group. On a large project, to make such a sweeping change requires one to:
    1. Wait for all 200 files to become unlocked so you can check them out.
    What large project is seriously using crappy file-locking source control like VSS? That sounds very, very painful, and would more or less make any sweeping refactoring impossible. IMO any non-trivial project needs an occasional housecleaning run like that, unless it is (A) immaculately designed, or (B) has the great luck of having requirements that aren't moving targets (ha!).

    Agreed that this isn't a WTF, though. It's just a mildly lazy refactoring, probably trying to avoid the kind of pains you're talking about. And when you consider the pass-through get/set accessor methods or properties littering every Java / C# codebase in existence, it's positively mundane.

  • Grant D. Noir (unregistered) in reply to savar

    If memory serves, the checkout-operation of clear-case does not lock the file in the repository (i.e. other developers can simultaneously checkout the same file, and edit it).

    But yeah, CC is a real pain. And dynamic views - there's your real WTF.

  • Matt (unregistered)

    As the person who posted it, this was called 3 times from the codebase and it was not a result of refactoring. It really was just an idiot trying to be clever, and failing miserably.

    Which is pretty similar to some of the responses on this thread!

  • Hubert (unregistered) in reply to GettinSadda

    It is called the Adapter pattern.

  • (cs) in reply to Iain Collins
    Iain Collins:
    Random832:
    however, it is a little-known fact that it is IMPOSSIBLE to do a 'fancy confirm box' - the only functions that can block execution in javascript are alert, confirm, and prompt.

    You can trivially just check the return value of a function and then proceed based on what it returned, use try/catch or - and this strikes me as the most sensible approach - just attach an event to the okay and cancel "buttons" on the DHTML confirm box - an event to a handler which is able to reference an object which it then performs an action when triggered (and so which executes code on confirmation, or doesn't, as the case may be).

    Right, but you can't, without using confirm or prompt, write a function which A) you call it B) it waits for user input C) it returns. My point was, that something like you described would require a rewrite of all code that calls this function anyway.

  • (cs) in reply to Jack
    Jack:
    Ok, my WTF is with your steps...

    3.) "confirmMessage" to "confirm" shouldn't need a unit test... unless you are real bad at typos.

    Wrong. Every single change gets tested. Period. If you change something that affects 200 places in the code, all 200 changes get tested. Anything less means you're not testing at all, and that's sloppy.

    Jack:
    4.) 1 check-in 200 files, 1 comment, 1 reference to the defect

    Again, wrong. The change should be commented with every one of the files checked in, so that it's history is properly tracked.

    Jack:
    5.) seriously, no. test once, but thats it.

    Seriously, wrong. See my comments above.

    Glad you don't work with me. I have enough to do without trying to keep track of some sloppy amateur's work as well.

  • (cs) in reply to vt_mruhlin
    vt_mruhlin:
    "But testing every page for every change is a pain", the testers say. Well, is testing in this case is just as necessary as it is if I replaced all those references to confirm(). So if you're comfortable doing less testing in this case, why not slack off in the other case too?

    The difference is that replacing it with a single call confirm() is provably equivalent - which can't be said for anything else (even replacing it with a prompt() that asks you type "yes" or "no")

  • (cs) in reply to jpd
    jpd:
    Now, the "greap[sp]+sed or awk" guy is either joking, or spends his days whipping up inconsequential perl scripts in his basement.

    Agreed. And not many days, either, or he'd be able to spell grep.

Leave a comment on “How Did No One Think of this Before?”

Log In or post as a guest

Replying to comment #:

« Return to Article