- 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
tacostand.php
Admin
function ReturnFirst() { return "fist"; }
Admin
You're laughing now, but all your code will break when they change the syntax of '<', '>' etc. With this code, you'll only have to replace it in one function.
Brillant!
Admin
I'm very impressed by the use of the explode() function.
I'm not too familiar with PHP, but this appears to be the finest example of self-documenting code that I've seen for a long while...
Admin
function WTFPost($postType) { if $postType == "Wooden Table" return "WTF"; if $postType == "QuickBasic" return "WTF"; if $postType == "Enterprise" return "WTF"; if $postType == "Paula Bean" return "WTF"; return "The real WTF is..."; }
Admin
Forgive me as I am PHP challenged:
so: truth('Absolutely No Fucking Way') and: truth('FALSE')
both yield true?
Admin
Admin
Actually, this makes me think that those scripts were ported from some kind of other language, or generated by some 'multi language' tool. Now that is some feature! You just have to output the functions like MatchField instead of language native crap and you run everything through your own lib! Portability yay!
Admin
TRWTF is that his truth test can't handly FileNotFound.
Admin
... not because there's anything wrong with PHP, but because so many stupid people use it. When you lower the bar so low all kinds of garbage gets in.
Admin
Ok, so which widely used, open source PHP-based project is this from? phpBB? Wordpress? Drupal? ;-p
Admin
Other than the disgusting waste of resources/program flow in order to make a simple test that is executed on the hardware/ASM level in most architectures, yes that is a feature.
If you wanted to make it a true feature, it would be done with a #define (or equivalent) to not waste program flow on it. If you hate #defines (and who doesn't?), then you could upgrade it to an inline function (or equivalent).
As is, the compiler/assembler will make a label for the function. Then, the program will load all registers onto the stack, jump to the subroutine by loading the memory address, execute the FIVE assembly-level statements (load 2 values, compare, store 2 values back), jump back to the program, and then unload the registers. With an inline, you could cut this down to 5 assembly instructions (but more time compiling). With a #define, you can cut time in both directions.
I wouldn't be surprised to see a memory leak in there too... Do people seriously think that computers are magic?
Admin
...but you see, my new, improved, wheel's much better. It's only got four sides. And if you leave it on a hill, it doesn't roll away...
Admin
Well, it's actually the best written code I've seen here in a while.
Pointless and wasteful, but readable.
Admin
Too bad if want to use the same field name for POST & GET methods at the same time :(
You'd have to do it the unportable, un-future safe 'normal' PHP way.
Admin
Sometimes I see code here that make me think it's about time we adopt procedure SDMBS-T Stupid Developer Must Be Shot - Twice
Better to shoot once in the head and once in the butt. Just to play safe because we have no idea where his brain might be.
</homicidal> </maniac>Admin
Disclaimer: I fail to see the sarcasm.
So, um, this isn't C/C++. In php, there only way to get memory leaks is by doing known (hopefully) no-nos, such as circular references. php is a latent-typed, garbage collected language, you know...
As for wastefulness, a good compiler can do compile-time evaluation of certain functions, and this one would be a good candidate. Although such optimizations are more common in languages where the compiler can interpret the code during compilation (Scheme, Lisp, ...), php (just as any other language system) could in principle optimize this function out as follows:
This can be thought of as compile-time macroization.
Having written a hacked-up Lisp-like system where this optimization is always done bar compile-time cut-offs, I'd say that your point is kinda moot in principle, but valid for IMHO broken implementations of most languages, whether otherwise thought of as "cool" (say OCaml) or "uncool" (say C).
Cheers!
Admin
Yes, and the magic works until you let the smoke out.
Admin
Actually it returns whatever you gave it.
Admin
Not that this contradicts anything you said.
Admin
Argh, my head
s.Admin
dumbest, shit, ever:
function queryStringToArray($queryString) { global $GL_strlen; global $GL_strpos; if ($GL_strlen($queryString) == 0) { return array(); } $queryArray = array(); $args = explode("&", $queryString); for ($i = 0; $i < sizeof($args); $i++) { if ($GL_strpos($args[$i], "=")) { list($param, $value) = explode("=", $args[$i]); $queryArray[$param] = $value; } else { $queryArray[$args[$i]] = ""; } } return $queryArray; }
Admin
Why would they want to change syntax of ">" "<" etc...? - those are quite fundamental operands in most of programming languages(I used "most" just in case there are some I am not aware about).
Admin
They should have taken a picture of the monitor with the code in the IDE, using a film camera, then gotten it developed, then taken a picture of the photograph using a digital camera, (with the photograph on a wooden table)...
Oh yeah, and the code is supposed to make it more like Lisp, making it more Enterprisey.
Oh, and was the programmer's name Paula?
Oh, and I wrote a CGI daemon in QuickBASIC which runs a forum:
http://samanddeanus.no-ip.org/forum
Sources: http://samanddeanus.no-ip.org/start.bas http://samanddeanus.no-ip.org/reply.bas
Admin
You may want to have your sarcasm detector adjusted.
Admin
This code has the truth !
Ahhhh ! PHP... Producing noob programmers since the beginning.
CAPTCHA was 'nobis'... no(o)bi(e)s
Admin
Scheme/Lisp? Then they'd be built in FUNCTIONS so ha.
Admin
Laugh if you will, but I use this particular construct when checking info which can originate from a Web page (check box/ radio button), a database ('t' or boolean), or a language construct (boolean).
Why repeat the entire test all over the place when a simple function call will do? And if you need to add another test for true/false, then you simply adjust the one function.
But I would return 'true' in the else.
Admin
I find it amazing that nobody noticed that you could write the queryStringToArray function like this:
function queryStringToArray($queryString) { parse_str($queryString, $newarray); return $newarray; }
It's always a bad sign when people write functions to duplicate built in functionality.
Admin
I'm betting that at one point there was a database involved somewhere, or that they planned to have one. The first value was supposed to be the name of a column, and the function's original name was something like CheckSessionValue.
Or maybe they're just enterprisey.
Admin
that function
would be soo much faster with a switch statement :/Also I guess it's good that ReturnTrue() doesn't return false...
Admin
Real Enterprisey (c) would be as follows:
This allows for instant configurability via a database, and has the added benefit that you can add distributed grid networking by ensuring that $db refers to an object encapsulating some sort of RPC.
I'm still a little concerned about the "1" though.
Admin
Very impressive post. I'd almost believe that you had a clue about the subject, except for the fact that you're spouting all that stuff about assembly instructions, registers, and jumps, and totally missing the fact that this is PHP, which is interpreted. In other words, all you did was post non-applicable information.
Nice try, though. If it hadn't been so far out of context, it might have been an impressive post.
Admin
Any language that can produce a syntactic wart such as "===" is quite capable of such behaviour.
I look forwards to PHP6 with trepidation.
Admin
function truth($fieldValue) { return "You can't handle the truth!"; }
Admin
Hah, this is not really all that bad. On my previous job, people would most likely write it as:
I hope you are being sarcastic.
Admin
Yeah, PHP has so little built-ins anyway right ? You'd have to print a 500 page book only to list them all...
This guy was bad for sure... Really... But please stop saying "Oh, but there's a function for that in PHP, loser". I'm pretty sure you've done a function or two that replicates a PHP built-in.
Admin
FORTRAN uses .LT., .GT., .EQ. and so on
Admin
TRWTF is that he explodes the string (poor thing) instead of using his indexof function. To be useful it should be used more often.
Admin
BTW, maybe this guy wrote all that stuff in PHP version 0.1 and all our wisdom wasn't applicable at that time???
Admin
So the obscure function checks for $plaintext, but if it's not found, adds urlencode($plaintext)?
Admin
Yes, but Fortran 90 and later can also use <, >, ==, /= (for "is not equal to"), >=, <=, etc.
Admin
This means than that his function is really useful as he could compare then even in Klingon
Admin
Perhaps it's time to give up programming in any language whatsoever and just express myself in unadulterated predicate logic.
Admin
Don't worry, just keep going until Xmas 2012 and all your problems will vanish all of a sudden.
Admin
Heh, that was a nice attempt at sounding intelligent and knowledgeable. Failed, but nice attempt. What, exactly, are you talking about that's relevant to this article? The code would have generated far more than "FIVE" instructions in all cases, because it's not running natively to begin with.
Admin
It is unlikely that PHP would change the meaning of "<", ">", or "==".
PHP being PHP though,it is easily conceivable that they would deprecate those operators in favor of (respectively) "lessThan", "is_greater_than", and "equals"
Admin
oh man, i just had to work on a site for a client and found that very MatchField function in the codebase!
it must be listed on some crap php development site somewhere. sad how the interwebs corrupts completely.
Admin
A more robust version of IsTrue in c#:
public bool IsTrueN(bool value, int times) {
for(int i = 0;i<times;i++) { value = !!value; } return value; }
making the wtf even wtfier.
Admin
In fairness to PHP, though, it's not really an Enterprisey language, is it? Java is so much better at this sort of thing.