• (cs)

    I cant understand php, but i hope tha this snippet doesn't search on google for the app page the user had requested ^^'

  • (cs) in reply to Vaitrafra
    Vaitrafra:
    I cant understand php, but i hope tha this snippet doesn't search on google for the app page the user had requested ^^'

    Why not? It's brillant! Hard Coding is for little heads that can't think ahead two weeks. Sure, you could write your own service to handle requests for the address of other services, but that would basically be a search engine. Why waste time trying to out-google google ?!?!?!

  • Ed (unregistered)

    That code is self documenting...

    Would you rather have a manual with huge bold text that said QUIT NOW OR YOU WILL BECOME ONE OF US, ONE OF US, GOOGLE GOBBLE, ONE OF US!

    on a side note, I know little PHP, but I was able to figure out what it was doing...

  • (cs) in reply to Ed
    Ed:
    That code is self documenting...

    Would you rather have a manual with huge bold text that said QUIT NOW OR YOU WILL BECOME ONE OF US, ONE OF US, GOOGLE GOBBLE, ONE OF US!

    on a side note, I know little PHP, but I was able to figure out what it was doing...

    The (seemingly bizaare) short variable names are directly related to the parameters in a google search string. So, actually, they make sense.

    {in a "back-handed" sort of way}

  • (cs)

    A lesson well learned, there is no such thing as a minor change. Allow 3 to 4 times as much time as you think it's going to take and you'll be fine.

  • Joe (unregistered)

    Fifth!

  • max (unregistered)

    You'll see what this code is used for the day google decides to redesign its results page...

  • anon (unregistered)

    i admit, after almost 20 seconds of looking at teh codez, i had to close my eyes.

    The googles, they do nothing.

    captcha: damnum

  • 1337 (unregistered) in reply to T $

    You know, you shouln't try to contradict Hofstadter's Law..

  • tardibear (unregistered)

    Why does the constructed search url include 'safe=off'?

    I wonder what sort of content the Google search is designed to locate ..

  • Mr. Boo-urns (unregistered)

    The lesson being: seppuku.

  • I walked the dinosaur (unregistered)

    That's exactly cleaner than some php code...and it's in a class!!!

  • Harry (unregistered)

    The real WTF is that there are still [software development] virgins out there.

  • Boiss (unregistered) in reply to I walked the dinosaur

    BTW... The problem with this code is that google changed

    in results for

    a couple months ago.

    I am maintaining a php app that was coded the same way... the easiest way to fix it and maintain it for a long time is to change the DAMN strpos to find results for regexp !

  • (cs)

    Of course, everyone knows that when you put several statements on one line, your code runs faster!

    But then there's that big block in the middle that's heavily indented... that's going to be a problem there, all that whitespace will block up the CPU pipeline (they clog even easier than Internet tubes).

  • anonymous coward (unregistered)

    Okay Jess, I don't want to hurt you feelings but if you can't read that code TRWTF was your hiring. Plus, the original developer seems to be quite a lazy ass but he's likely to be more capable to get things done. Sorry, but that CodeSOD is boring.

  • (cs)

    Ooh! Minified PHP code - it saves lots of bandwidths!

  • (cs)

    I wonder if the author of this project is the same guy who wrote/customized my soon-to-be-ex employer's "ERP" (using that term loosely) system? While my project is written in VBScript and Classic ASP, the rest of the signs are pretty darn close.

    We need to shoot people like this, on sight. They ruin this field for the rest of us who actually know what the fuck we are doing.

  • Ed (unregistered) in reply to ObiWayneKenobi

    There are people who know what they are doing? This has yet to be be proven. I don't know what I'm doing over 99% of the time because my PM's don't know what they are doing... Where do you work at and are you hiring more programmers? :)

  • (cs) in reply to ParkinT
    ParkinT:
    The (seemingly bizaare) short variable names are directly related to the parameters in a google search string. So, actually, they make sense.
    $q does, sure. $n stores the page number, I think. $u stores the URL of the Google search page, $html stores the HTML result (z0mg, a relatively-sane local variable name). $p the position of the start of a result (except, as Boiss mentioned, it won't work as Google have reworked their results page since this was written). $a and $b store the start and end of various things it's trying to extract, and $r stores all the information for the result.

    Obviously, the right way to do this would be to take the Google search page, parse it as HTML, and run XPath or similar over it... //*[@class="g"]//a[@class="l"]/@href - suddenly the change from from

    to

    is no longer a problem... it's completely unbreakable!

  • Scott (unregistered)

    I'm way to tired to even work out what that does. But even if I was awake, I don't think it would help.

  • (cs)

    So is this now a place to post WTF code that we are trying to figure out at work, and get the community to figure it out for us? Wish I'd known that a few years ago; would have saved me some head scratching.

    OTOH, it seems only one step above "send me teh codez, plz".

  • Ritchie (unregistered)

    My first thought on seeing this was "this is autogenerated code".

    To play Devil's advocate, I've got compilers and code generators that spit out stuff like this when it's the best way to reduce the amount of code a human has to read and write overall. They might be a directory elsewhere with some Wasabi code in it ;-D

    (Except my generated files usually have a comment at the top SAYING what autogenerated it and where the original source can be found...)

  • cod3_complete (unregistered) in reply to Phlip
    Phlip:
    Of course, everyone knows that when you put several statements on one line, your code runs faster!

    But then there's that big block in the middle that's heavily indented... that's going to be a problem there, all that whitespace will block up the CPU pipeline (they clog even easier than Internet tubes).

    HA yep there really are tons of l33t coders out there who genuinely believe that several statements packed on one line actually makes the code faster. 1 letter variables and zero comments sheesh. Darth Vader coder: 'If you only knew the power of the spaghetti code.' Me: 'Nooooo...I'll never join yooooou.'

  • Eric (unregistered) in reply to T $

    We never learned what the "minor change" was. So far there has been a lot of searching though files and code, but no changing. So the change might still be minor.

  • Nodren (unregistered)

    I ran this through zend studio real fast, it doubled the lines of code, whoever wrote that snippet has no idea what whitespace is.

    <?php
    class GoogleSearch {
    	var $url;
    	var $lang;
    	var $cookie;
    	var $query;
    	var $rpp;
    	var $ra;
    	var $rb;
    	var $results;
    	var $referer;
    	var $nresults;
    
    	function GoogleSearch() {
    		$this->url = 'http://www.google.com/';
    		$this->lang = 'en'; 
    		$this->rpp = 100;
    		$this->ra = 0; 
    		$this->rb = 0; 
    		$this->query = ''; 
    		$this->nresults = 0;
    		$html = Browser($this->url); 
    		$this->cookie = GetCookies($html);
    	}
    	function GoogleQuery($q,$n=1) {
    		if (!($q == $this->query && $n >= $this->ra && $n <= $this->rb)) {
    			$u = $this->url.'search?q='.urlencode($q)."&num=".$this->rpp."&hl=".$this->lang."&lr=&safe=off&sa=N";
    			$this->ra = (($n-1)-($n-1)%$this->rpp)+1;
    			$this->rb = $this->ra + $this->rpp - 1;
    			if ($n > $this->rpp) {
    				$u .= '&start='.($this->ra-1);
    			}
    			$this->query = $q;
    			$html = Browser($u,'GET','',$this->cookie,$this->referer);
    			$this->referer = $u;
    			$this->results = array();
    			$p = 0;
    			do {
    				$p = strpos($html,'

    ',$p); if ($p !== false) { $r = array(); $a = strpos($html,'"',$p+11)+1; $b = strpos($html,'"',$a); $u = substr($html,$a,$b-$a); if (substr($u,0,4) === '/url') { $u = substr($u,strpos($u,'&q=')+3); } $r['url'] = $u; $a = strpos($html,'>',$b)+1; $b = strpos($html,'</a',$a); $p=$b; $r['meta'] = strip_tags(substr($html,$a,$b-$a)); $a = strpos($html,'<font',$b); $b = strpos($html,'Similar pages',$a); $u = substr($html,$a,$b-$a); $b = strpos($u,'color=#008000>'); if ($b !== false) { $r['content'] = trim(strip_tags(strtr(substr($u,0,$b+14),array("
    "=>" ")))); } else { $r['content'] = ''; } $this->results[] = $r; } } while ($p !== false); $a = strpos($html,'of about '); if ($a !== false) { $a += 12; $b = strpos($html,'</b',$a); $this->nresults = strtr(substr($html,$a,$b-$a),array(','=>'','.'=>'')); } else $this->nresults = 0; } $u = $this->results[$n-$this->ra]; return $u; } function ResultsNumber() { return $this->nresults; } } ?>

  • (cs) in reply to Skaven
    Skaven:
    Ooh! Minified PHP code - it saves lots of bandwidths!
    CPUs have bandwidths now??? How many? I hope they don't get slashdotted!
  • Anon (unregistered) in reply to Phlip
    Phlip:
    ParkinT:
    The (seemingly bizaare) short variable names are directly related to the parameters in a google search string. So, actually, they make sense.
    $q does, sure. $n stores the page number, I think. $u stores the URL of the Google search page, $html stores the HTML result (z0mg, a relatively-sane local variable name). $p the position of the start of a result (except, as Boiss mentioned, it won't work as Google have reworked their results page since this was written). $a and $b store the start and end of various things it's trying to extract, and $r stores all the information for the result.

    Obviously, the right way to do this would be to take the Google search page, parse it as HTML, and run XPath or similar over it... //*[@class="g"]//a[@class="l"]/@href - suddenly the change from from

    to

    is no longer a problem... it's completely unbreakable!

  • jimi (unregistered) in reply to Joe
    Joe:
    Fifth!
    You're still the first idiot in my opinion...
  • (cs)

    SpectateSwamp would be proud.

  • Jess (unregistered)
    Okay Jess, I don't want to hurt you feelings but if you can't read that code TRWTF was your hiring.
    Actually, the written article excluded quite a bit of my submission, and while I don't have my actual submission to double check, the quotes themselves don't sound remotely like me. (Also, I wasn't 'hired'. This was a freelance project)

    That said, the article gets the jist... But the WTF wasn't that I couldn't read the code. The WTF was that there were gigs of content (literally), broken up into more files than I could sift through, and not a single comment anywhere therein. That code wasn't what I was looking for, it was just an example.

    Take a look at the file list:

    engines_2.php   engines--.php   engines_old.php   engines-.php
    engines_2007-05-01.php -engines-.php engines.php
    (and so on). It'd be nice if I could have assumed that "engines.php" was the file being used and all the other ones were just backups, but unfortunately, as I found out later, that wasn't the case. (It was a couple months ago, but I recall engines--.php being the current file. Notably, it had similar content as the rest, but vastly different code)

    So yeah, the code in the submission is readable. Sure, I know exactly what it's doing just by looking at it. But, imagine sifting through hundreds of files, thousands of lines long, all formatted in that way. Multiple statements per line, variable declarations (with no comments) that are 2-3 characters... no spacing... screwy indentation...

    Also, the project manager refused to give me ftp access in fear that I'd steal all his code (and would have dropped me if he caught me using scp, or similar). While formatting could have been autocorrected in an IDE, in this project it was vi or finding a new client.

    Since no one on -his- team knew anything about ANY of the code (he hadn't even hired a single programmer to maintain it), after finishing up the work he had asked for, "find a new client" is just what I did.

  • Jason (unregistered)

    That's what you get for being a web programmer.

  • Dana (unregistered) in reply to 1337
    1337:
    You know, you shouln't try to contradict Hofstadter's Law..

    A friend once told me that you should multiply all software time estimates by a factor of pi to get a more reasonable estimate (pi/2 if you've done it before).

  • (cs) in reply to cod3_complete
    cod3_complete:
    HA yep there really are tons of l33t coders out there who genuinely believe that several statements packed on one line actually makes the code faster. 1 letter variables and zero comments sheesh.
    Are you sure they're 133t coders? This was actually true back in the days of built-in BASIC on the TRS-80 CoCo and so forth. The magazines of the day used to publish code like that, all jammed together, and the numbered lines with intervals of 1 rather than 10. But I doubt there are "tons of 133t coders" who are old enough to even know what TRS stands for.
  • (cs) in reply to anon
    anon:
    The googles, they do nothing.
    Bravo!
  • (cs) in reply to anon
    anon:
    The googles, they do nothing.
    Clbuttic!
  • santa c (newtothis) (unregistered) in reply to cparker

    it sure does save ALOT of bw for tdwtf and viewers...

    and yes mate, anywhere there's info transfer, there's bw - cpu-mem and such... dont patronize us n00bs!

  • santa c (newtothis) (unregistered) in reply to cparker

    sorry for posting twice... so that's what the quote button's for...

    cparker:
    Skaven:
    Ooh! Minified PHP code - it saves lots of bandwidths!
    CPUs have bandwidths now??? How many? I hope they don't get slashdotted!

    it sure does save ALOT of bw for tdwtf and viewers...

    and yes mate, anywhere there's info transfer, there's bw - cpu-mem and such... dont patronize us n00bs!

  • 54n74 c (newtothis) (unregistered) in reply to FredSaw
    FredSaw:
    cod3_complete:
    HA yep there really are tons of l33t coders out there who genuinely believe that several statements packed on one line actually makes the code faster. 1 letter variables and zero comments sheesh.
    Are you sure they're 133t coders? This was actually true back in the days of built-in BASIC on the TRS-80 CoCo and so forth. The magazines of the day used to publish code like that, all jammed together, and the numbered lines with intervals of 1 rather than 10. But I doubt there are "tons of 133t coders" who are old enough to even know what TRS stands for.

    0hh d00d, j00 c0uldn'7 b 4ny m0r3 wr0ng... 3v3ry c00l ch4p 0nl1n3 kn0wz w07'z 7h1z R34lly 5ux

    and for the cooler peeps...

    0## d00d, j00 c0|||d||'7 b 4||'/ |/|0r3 //r0||6... 3/3r'/ c00| c#4p 0|||1||3 |<||0//2 //07'2 7#12 R34||'/ 5|_|x

  • (cs)
    "As for what this file does... how it's being used... if it's being used... I still have absolutely no idea.

    And you call your self a programmer?

    It checks the position of a given page in the google SERP's.

    Looks much like mine code ... tho I've put comments almoust every second line since I've first time forgotten what the code did a year after finishing it.

  • jumentum (tego) (unregistered) in reply to BTMPL
    BTMPL:
    ... tho I've put comments almoust every second line since I've first time forgotten what the code did a year after finishing it.

    ... and YOU call YOURSELF a programmer??

  • nanoman (unregistered) in reply to jumentum (tego)
    jumentum (tego):
    ... and YOU call YOURSELF a programmer??

    I don't know what YOU do for living, but if you code every day, you can't remember any detail of how you implemented things without taking a long, deep look at it.

  • Dave C. (unregistered) in reply to FredSaw
    But I doubt there are "tons of 133t coders" who are old enough to even know what TRS stands for.
    It stands for Tandy Rules, Suckas!

    10 HOME 20 SWEET 30 GOTO 10

  • Joon (unregistered) in reply to nanoman
    nanoman:
    jumentum (tego):
    ... and YOU call YOURSELF a programmer??

    I don't know what YOU do for living, but if you code every day, you can't remember any detail of how you implemented things without taking a long, deep look at it.

    I must disagree. If you wrote your code well in the first place, you, or any other programmer, should be able to come back in 1 or 2 or 10 year's time and still understand what it is meant to do.

    And by "writing your code well" I mean: Process:

    • Document your architecture, not your implementation
    • Don't fall for NIH

    Code:

    • Define and stick to project standards. You should have standards for code format, implementation conventions, naming standards, architecture etc.
    • Comment only your intent
    • Use descriptive variable and procedure names
    • Write well factored code that does not duplicate things all over the show
  • Jess (unregistered) in reply to BTMPL
    "As for what this file does... how it's being used... if it's being used... I still have absolutely no idea.

    And you call your self a programmer?

    You should read my comment earlier on. I actually don't remember submitting that I didn't understand what the code did... but if I -did- say that, I meant I didn't take the time to actually sort through the poorly formatted eyesore, not that it was in any way complex.

    I -did- submit that I didn't know if it was being used... and TBH, I still don't know if a lot of it was. I don't tend to spend my time obsessing over other people's garbage.

    I did what I was asked to do, but signing up for a "small" project like that is -not- a mistake I plan on making again.

  • Opie (unregistered) in reply to Phlip
    Phlip:
    ParkinT:
    The (seemingly bizaare) short variable names are directly related to the parameters in a google search string. So, actually, they make sense.
    $q does, sure. $n stores the page number, I think. $u stores the URL of the Google search page, $html stores the HTML result (z0mg, a relatively-sane local variable name). $p the position of the start of a result (except, as Boiss mentioned, it won't work as Google have reworked their results page since this was written). $a and $b store the start and end of various things it's trying to extract, and $r stores all the information for the result.

    Obviously, the right way to do this would be to take the Google search page, parse it as HTML, and run XPath or similar over it... //*[@class="g"]//a[@class="l"]/@href - suddenly the change from from

    to

    is no longer a problem... it's completely unbreakable!

    The only real problem here is that google does not use XHTML, so this is not, in the strictest sense, a valid solution. HTML is not a subset of XML, so XPATH is not guaranteed to work in all situations.

    Use a regular expression and call it a day.

  • (cs) in reply to Opie
    Opie:
    The only real problem here is that google does not use XHTML, so this is not, in the strictest sense, a valid solution. HTML is not a subset of XML, so XPATH is not guaranteed to work in all situations.

    Well, the "parse the HTML" step would obviously have to involve a tag soup parser at some point... Google's HTML isn't valid, after all. But I maintain that once the HTML is parsed into a document tree, the fact that it's not really XML shouldn't matter, and XPath'll work.

    Also: That's certainly not the only real problem with the suggestion. Seriously.

    Also also: The non-joking real way to do it is with this. Or something like it (I'm not sure if that's the exact right project, but there'll be something on that site that does what they want).

  • Jazz (unregistered)

    The Real WTF is that Alex will take this as more evidence that PHP is a horrible terrible language instead of blaming the poor demented soul who actually wrote the code.

  • Edward Royce (unregistered) in reply to Dave C.
    Dave C.:
    But I doubt there are "tons of 133t coders" who are old enough to even know what TRS stands for.
    It stands for Tandy Rules, Suckas!

    10 HOME 20 SWEET 30 GOTO 10

    Actually what it stands for is:

    "You bought a TRS-80 Mod III with 16k RAM for $1,000 and the Commodore64 just came out? You're f**ked!"

  • anonymous coward (unregistered) in reply to Jess
    Jess:
    Actually, the written article excluded quite a bit of my submission, and while I don't have my actual submission to double check, the quotes themselves don't sound remotely like me. (Also, I wasn't 'hired'. This was a freelance project)
    Sorry for the sarcasm, it feels like the story misses the point then ( hence the clueless replies which encouraged me to comment - there is so much more awful code out there, this one is just average crap ) ; I understand it's quite hard to picture that kind of situation in a short article ... it must be frustrating to get through that nightmare and not even find some funny punchline ;-) The point should be the usual management short-vision antipattern, I guess.

Leave a comment on “A Rather Minor Change”

Log In or post as a guest

Replying to comment #193132:

« Return to Article