- 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
lol omigosh frist!!11!!
Admin
So realyl, it doesn't matter if you are logged in. The || essentially makign it so if you are logged in you can upload, if you are not logged in, you can upload, because in our reality 2+2 does equal 4. Why not do away with the check in it's entirety? You will get the same results.
EDIT: Just thought of a reason for this. It is to prevent anyone using one of those really old pentium processors where 2 might become a float and the math error might make 2+2 != 4.
{shoots pinkie pie with caffine to watch her spontaneously explode}
Admin
I forgot my password, would you clear it?
Admin
You don't say.
Admin
if frist { postcomment("Frist!!>!@!@12!!"); } else { postcomment("Frist!!>!@!@12!!"); }
Admin
In abadabad code throws you
Admin
I'm just looking at the WTF in the text: I started sifting throw hundreds Should it not be I started sifting through hundreds
Admin
Looks like an "always true" clause added in the condition to force the behavior, probably temporarily for debugging purposes.
TRWTF is the lack of comment/TODO/etc. about it and the fact it was checked in.
Admin
Big Brother had decreed that your conditional expression not evaluate to true. Can computers doublethink?
Admin
normally if you want to force a true you add "|| true" not a math function. Reminds me of the shirt: 2+2=5 For extremely large values of 2
Admin
Admin
You are correct. TDWTF needs to hire some proofreaders, stat.
Admin
Thanks KattMan for the explanation! Couldn't have done it without you.
Admin
Admin
It's obviously debug code that either the original developer forgot to take out, or was purposely left in to bypass having to constantly log in. Since it was an unfinished project it's likely the latter and the new guy needs to get off his high horse. In my experience many developers when having to take over a new project will trash the work of the previous generation since it's easier to do than actually having to really learn the architecture.
Admin
Could make sense as a temporary debugging change, to force the login to work while testing.
A distinctive "true" value is easier to remove when testing is done.
When it's time to remove the bypass, which would you rather search for: "true" or " || 2+2=4" ? You probably don't want to blindly remove all "true" strings but you can safely search&replace " || 2+2=4" with "".
Admin
Admin
Not if you're a banker!
Admin
This remine me level of security here in Abadabad.
[image]Admin
Thanks so much for explaining this! As a programmer I would NEVER have understood programming language logic and feel that such a joke obvious to the visitors of this website needed a full explanation.
Admin
By golly, I think you've solved it.
Admin
In my country we frist lern to spel and than we proveread.
Admin
No good, because what if 2 changes so that 2+2 no longer equals 4? Should be "|| 2+2 == 2+2", so even if 2+2 = 6, it will still evaluate correctly.
Admin
Cake or death?
Admin
Seriously guys, that's like basic optimization knowledge.
Yes, 2+2==4 is always true, but as it is an expression it is not for free. Now if logged_in() is true, 2+2==4 does not have to be evaluated at all, saving valueable processor time.
Admin
It's clearly debug code. I on the other hand actually have "where 1 = 1" code in production. And I don't consider it a WTF. When appending various conditions to dynamic sql it's easier to start with a no-op condition and then append all the other conditions starting with "AND" without keeping track of "is this my first condition? no? then throw in and".
Admin
This is obvious not C-based language. Sometime, developer is taking order-of-opeation for granted. Also, evaluation of OR is not treated seme in all language.
Admin
Admin
You are all welcome, I have fulfilled my public service for the year, thanks to all of you that listened.
Admin
Actually, the code might have a pretty legit reason. In some cases you can not just put "true" into "if" condition if there is "else" branch in the code, the compiler will complain about unreachable code.
Seeing this in the production code kind of sucks though.
Admin
If 2+2==4 is his favorite debugging alias for "true" then it's easier to search for to remove later. It's a built-in todo.
Still dumb, but that's the thought process.
I've gotten very good as learning to think like the retard I have to clean up after.
Admin
Its a valid check that users from other dimensions, where Maths is fundamentally different, from accessing the upload functionality.
Admin
Using debug code? Pick one from the list above.
Admin
Or you are living in Airstrip One!
Admin
The very first infinite loop I wrote when I was a noob looked like this:
I thought I was so clever.
Admin
What's in logged_in() ?
A throw perhaps?
Admin
I've got it! If the program is being run in an alternate universe, then 2+2 might not equal 4. If this is a case, THEN we check to see if the user is logged in or not.
Admin
Actually it MAY matter... perhaps the latest version throws and exception in the if condition when the user is not logged int.
Admin
This is big brother protection.
In case the government decides that 2 + 2 = 5, the code will actually require someone to be logged in.
Admin
Which is exactly what's wrong with the whole "try/catch let's pretend we've got objects in our made up computer world" style of programming.
Now get off my nicely block structured lawn.
Admin
Big Brother says 2 + 2 = 5.
Admin
I had looked through briefly but missed your comment. Serves me right for making coffee instead of reading TDWTF. Glad someone else had a similar thought.
Admin
#ifdef REQUIRES_LOGIN #define 4 5 #endif
Admin
" || debug_mode" would be even easier to search for.
Admin
Admin
Admin
proughreaders, surely
Admin
Since you are dynamically building an SQL statement, I'll assume you are using PHP.
Put all your WHERE clauses into an array, then use
implode()
to join the arrays into a string.$where[] = "param1 = 'fish'"; $where[] = "param2 = 'slap'"; $sql = "SELECT * FROM table WHERE " . implode(" AND ", $where);
Admin
more likely a throw_up();
Admin
Not only that, but there are quite a few compilers out there that won't allow you to write conditions that simply evaluates to either true or false, i.e. if(false) { ... }, because that produces unreachable branches. That includes things like if(expression || true) or if(expression && false) and things like that. The work around? ifdef (if there is a preprocessor); comment out the block; use conditionals (1==1, 2+2==4).
By the way, there is no real reason you can't search for "|| true" because the only time you should have boolean literals is when you initialize a variable. "true" or "false" should never appear within a test.
Just my $.02