|
|
|
| Hurry! Enter The Daily WTF's OMGWTF2 Contest by June 28th! - Prizes! Fame! Trophies! Do your worst: http://omg2.thedailywtf.com/ |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
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. |
Re: Authenticate or Math
2012-04-04 19:47
•
by
sa
(unregistered)
|
Egzackery....We have a captcha that requires some math, but the devs got sick of entering their details AND the captcha in the dev sandpit so they temproarily hacked it. 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 |
|
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... |
Re: Authenticate or Math
2012-04-05 00:32
•
by
Dirk
(unregistered)
|
And Akismet thinks this is fine??? WTF? |
Re: Authenticate or Math
2012-04-05 00:37
•
by
Dirk
(unregistered)
|
What if the value changes between the evaluation of the left and right hand operands? You're setting yourself up for a race condition there! |
Re: Authenticate or Math
2012-04-05 00:39
•
by
Dirk
(unregistered)
|
I hate lazy coders. |
|
After taking down three commenters in quick succession, I'll stop now.
Peace. |
Re: Authenticate or Math
2012-04-05 03:53
•
by
Aankhen
(unregistered)
|
Too bad function invocation isn’t supported outside conditionals, eh? |
Re: Authenticate or Math
2012-04-05 04:39
•
by
Will
(unregistered)
|
|
2+2=5
For sufficiently large values of 2 FTFY |
Re: Authenticate or Math
2012-04-05 05:08
•
by
Canonymous Oward
(unregistered)
|
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("") |
Re: Authenticate or Math
2012-04-05 05:26
•
by
Parasietje
(unregistered)
|
|
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' |
Re: Authenticate or Math
2012-04-05 06:24
•
by
retard fixer
(unregistered)
|
yeah thanks for pointing out php sucks again ... that's a really helpful and amusing point |
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. |
Re: Authenticate or Math
2012-04-05 10:16
•
by
DEEmery
(unregistered)
|
|
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?? |
Re: Authenticate or Math
2012-04-05 12:18
•
by
backForMore
(unregistered)
|
very 2+2=4 |
Re: Authenticate or Math
2012-04-05 12:43
•
by
Jay
(unregistered)
|
So wait, why did the chicken cross the road again? |
|
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: public BigDecimal calcSalesTax(int receiptNumber) { // TO DO: Get sales tax calculation in here // For now just return a dummy value return new BigDecimal("1.00"); } Ha ha! The programmer never really calculates the sales tax! What a moron! |
Re: Authenticate or Math
2012-04-05 12:58
•
by
Jay
(unregistered)
|
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. |
Re: Authenticate or Math
2012-04-05 12:59
•
by
Jay
(unregistered)
|
Or what if the reflexive property of equality ceases to hold? The problem is bigger than you think. |
Re: Authenticate or Math
2012-04-06 12:23
•
by
C
(unregistered)
|
DotNet has a similar feature, string.Join(" and ", conditionArray), but what if none of the conditions need to be added? His code still works, yours doesn't. |
Re: Authenticate or Math
2012-04-07 09:48
•
by
poon
(unregistered)
|
|
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.
|
I always replaced it with /**/... in case I ever had to go back (i'm alway paranoid about that and sometimes it pays off). eg replace " || 2+2==4" with "/* || 2+2==4*/" so that it would still be there but it wouldn't evaluate at compile time. I've also been told that i'm wierd. |
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. |
Re: Authenticate or Math
2012-04-08 10:17
•
by
veggen
(unregistered)
|
Psycho the rapist? That's how your mom calls me. |
|
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.
|
Re: Authenticate or Math
2012-04-16 19:10
•
by
Always Right
(unregistered)
|
|
What makes you think they're using source control?
|
Re: Authenticate or Math
2012-04-16 19:12
•
by
Always Right
(unregistered)
|
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. |
|
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 |
Re: Authenticate or Math
2012-06-09 16:18
•
by
tanus
(unregistered)
|
|
Your logic is flawless in any universe.
|
| « Prev | Page 1 | Page 2 | Page 3 | Next » |