WTF, PHP coder making it up as they go along



  • I'm by no means an expert coder, (self taught PHP coder, but at least aware enough to know that puts me at the very bottom of the coders foodchain) but I was astonished by some code someone showed me to carry out a simple math function.

    The task was to take unsigned short/word and convert the value range of 0-65536 to the value range 0.5 - 7.5.

    This guy came up with the incredibly imaginative solution of creating an array containing all 65536 possible values between 0.5 and 7.5:

    $convert_array = array();
    for (
    $i 0.5$i 7.5$i += 0.0001068115234375) {
       
    array_push($convert_array$i);
    }
     

    Then using the value of the short as the index in the array to get his value:

    $value = $convert_array[$short];

    Genius.

     

     



  • don't worry, i've seen worse.

    i was once asked to question someone who wanted to work at our company about there knowledge of php.

    So i asked a few standard webby php questions.

    "do you know about mysql injection, how could you prevent it", etc.. etc..

    it took a little while, but after about 15 minutes or so, i discovered this guy had never heard of arrays. he used mysql to create and fill tables. And used them in some twisted sense to store data in "arrays" (he actually refered to them as arrays instead of the more common rows or tuples)

    however he also used $_SESSION['wtf'] = 'bla' but apparently thaught that was just something special.
     

    i'm still puzzled as how you can get it so wrong, mysql_fetch_array should have been a hint at the very least.

    And the most fun part was that he already worked at a web shop, creating dynamic webshop kinda applications.

    as expected the goggles did very little.

    for those wondering.
    He didn't get the job.
     



  • [quote user="Colcob"]

    I'm by no means an expert coder, (self taught PHP coder, but at least aware enough to know that puts me at the very bottom of the coders foodchain) but I was astonished by some code someone showed me to carry out a simple math function.

    The task was to take unsigned short/word and convert the value range of 0-65536 to the value range 0.5 - 7.5.

    This guy came up with the incredibly imaginative solution of creating an array containing all 65536 possible values between 0.5 and 7.5:

    $convert_array = array();
    for (
    $i 0.5$i 7.5$i += 0.0001068115234375) {
       
    array_push($convert_array$i);
    }
     

    Then using the value of the short as the index in the array to get his value:

    $value = $convert_array[$short];

    Genius.

    [/quote]

    Oh, he's just trying to optimize the calculation. We all know that an array lookup is a lot faster than an addition and multiplication!

    Except, this is in PHP, and the array gets created every time. hmm... why not $value = $short/65535.0*7+.5

     



  • [quote user="stratos"]

    it took a little while, but after about 15 minutes or so, i
    discovered this guy had never heard of arrays. he used mysql to create
    and fill tables. And used them in some twisted sense to store data in
    "arrays" (he actually refered to them as arrays instead of the more
    common rows or tuples)

    however he also used $_SESSION['wtf'] = 'bla' but apparently thaught that was just something special.

    [/quote]

     Wow, I'm sure we've all occasionally written some function to do something before discovering there is already one in the library, but re-implementing an entire language feature is something else.

     



  • And I thought you were writing about the coders of PHP itself, not someone using it. Now they're truly making it up as they go along.

    [quote user="Colcob"] Wow, I'm sure we've all occasionally written some function to do something before discovering there is already one in the library, but re-implementing an entire language feature is something else.[/quote]
    Especially given that PHP's arrays are also PHP's hash tables, stacks and queues. They're rather hard to miss.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.