- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
x==true <!=> x becouse x <=> (x>0) && (true==1)
which gives x==1 <!=> x>0
captcha: craaazy, yepp that's me
Admin
Admin
ah! I get it, they forgot to return "Not Found"!
Admin
The correct way of doing this function is:
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.
Admin
Ok, I was going to reply the previous poster until I saw you. LOL
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.
Admin
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
Admin
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.
Admin
Signed, Strongbad.
Admin
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.
Admin
OK, I give up... what is the "GoF book"?
Admin
I must agree.. not a WTF. I was about to write exactly the same.
Admin
[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.
Admin
Admin
Admin
-Harrow.
Admin
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.
Admin
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.
Admin
harry potter and the Goblet of Fire, obviously
Admin
... 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?
Admin
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.
Different browsers do things differently, unfortunately.
Admin
um, yes they are.
Admin
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.
Admin
What browser has bugs related to confirm?
Admin
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;
Admin
Admin
You might want someone to take a look at your sarcasm detector.
Admin
Oh boy! CodeSOD, haven't seen one of these in an eternity...
well damn
Admin
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.
Admin
Paula would have written "GoF Bok"
Admin
Note, there is a Guru Form but I can't reveal what it is because then everybody would use it.
Admin
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.
Admin
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)
Admin
Oops, I just realised how long that post was!
Admin
Oops, I just realised how long that post was!
Admin
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.
Yes, this does actually work, and I have actually deployed it. I'm sorry.
Admin
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
Admin
Do you mean
return ((confirm(msg) == true) == true ) ? ( (confirm(msg) == true) == true ) : ( (confirm(msg) == true) == false );
perhaps?
Admin
I see this all the time, and even worse stuff. People just do not know their boolean logics.
Admin
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
Admin
Admin
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!
Admin
I blame Shakespeare, "To be or not to be?", it's just TRUE damnit!
Admin
Now, the "greap[sp]+sed or awk" guy is either joking, or spends his days whipping up inconsequential perl scripts in his basement. But..
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.
Admin
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.
Admin
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!
Admin
It is called the Adapter pattern.
Admin
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.
Admin
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.
Again, wrong. The change should be commented with every one of the files checked in, so that it's history is properly tracked.
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.
Admin
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")
Admin
Agreed. And not many days, either, or he'd be able to spell grep.