- 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
As others have said, the || clause is probably left from debug use.
As to why 2+2==4 rather than 1 or True, none of you seem to allow for humour. No doubt the programmer found it amusing to write it that way.
Admin
Then the testers wanted same in SIT...
Not really sure how it made production though. Never mind, the users don't seemed to have worked out they can put any value in our math captcha
Admin
There is also a chance that the getter for the logged_in boolean is overloaded to actually to log in the account if it is not. It could also log this activity.
This means that if an account has its details available but is not logged on or if it is logged on, it will write to the log.
It will let you upload even if it can't...
Admin
Admin
Admin
Admin
After taking down three commenters in quick succession, I'll stop now.
Peace.
Admin
Admin
2+2=5 For sufficiently large values of 2 FTFY
Admin
Which I do not really care about when I'm debugging the code this way. However, I do want the compiler to check that this code is compilable, so I'm not ok with just commenting it out.
The code is wrong though - it can be reduced by compiler to a constant. The Right Way (tm) in Java is to put something like "".equals("")
Admin
First rule of bad code: never assume a method is without side-effects! Maybe $this->ion_auto->logged_in() also parses the cookie and writes a global $user variable somewhere, which the $this->load->view('') method depends on?
Captcha: 'mara', ancient old Buddhist mantra meaning 'nothing is without consequence'
Admin
yeah thanks for pointing out php sucks again ... that's a really helpful and amusing point
Admin
Good call.
But in that case what ought to have been programmed was for the "or" condition to be something like "|| OverrideLogin" which would then be assigned the value "True" somewhere at the start / compile time / whatever level of control you'd need.
If in Java then you might use the technique of calling it OVERRIDE_LOGIN and declaring it as a public static final boolean.
You C-monkeys would probably use #Define in a precompiler.
Admin
And a really good compiler would optimize the whole check out, since it can prove that the right-hand side is always true, so the if condition is always true, regardless of what is returned by the left-hand side.
Right??
Admin
very 2+2=4
Admin
So wait, why did the chicken cross the road again?
Admin
As others have noted, this is pretty obviously debugging code. He did say it was an unfinished project.
I think I'll submit an hysterically funny WTF along the lines of:
I found this code in a project under development:
Ha ha! The programmer never really calculates the sales tax! What a moron!
Admin
Depends if the compiler is smart enough to figure out that the function has no side effects. "Optimizing away" functions with side effects is not an entirely good thing.
Admin
Or what if the reflexive property of equality ceases to hold? The problem is bigger than you think.
Admin
Admin
Yeah ^^ TRWTF is posting this article in the first place... it really just amounts to "oh look, someone forgot to take out debug code (and the other code sucked too, trust me)". Takes a shitty coder, and a shitty person, to get excited about that IMO.
Admin
I've also been told that i'm wierd.
Admin
Exactly.. this is not a WTF, it's just an example of someone forgetting a step, quite possibly because he or she was busy working bug reports / change requests.
Admin
Admin
As far as the atrocious standard of 99% of all PHP code goes, this is actually pretty good. The original developer at least had some understanding of functions and OO, two concepts that are normally harder to convey to PHP programmers than teaching your dog calculus.
Admin
What makes you think they're using source control?
Admin
Around these parts, we have a function called DevMode() which returns true when it detects that it's running on the dev server.
So it would look something like:
if ($this->logged_In() || Devmode()) ...
Devmode() returns false in production environments, true on dev/test environments.
Admin
Obvious leftover 'force this code path' hackery.
I myself am fond of temporarily removing code with
#if 6 == 9 ... #endif
http://en.wikipedia.org/wiki/If_6_Was_9
Admin
Your logic is flawless in any universe.