Skip navigation.
Home

I'm smrt.

Bad Architecture

I like to laugh at clever programmers that outsmart themselves. An anonymous user sent in the following.

<?php
/* query_fetch - a very smart function.
  It executes and fetches sql data, returning either a value, an array,
  or a multidimensional array depending on the query results
*/
function query_fetch ($query,$start=1,$max=1000)
   {
   ...
   }
?>

The WTF is what query_fetch() returns. Depending on what comes back from the database it returns a single value (1 row, 1 column), an array (1 row, multiple columns), or a multi-dimensional array (multiple rows and columns). Cool right? A single function that does all that... ohh very smart.

This function is pretty dumb ass because it might return a scalar one time and an array the next. But who the fuck cares that debugging becomes a nightmare, or that I have to write extra code?! It'll make me look smart and nothing like shows smart like adding unnecessary complexity and requirements!

Yea it's a pain in the ass that sometimes a scalar pops out and fucks up the code. The solution? Write a smarter function!

<?php
function fixate($item) {
if ((
$item)&amp;&amp;(!is_array($item))){ return(array(0=>$item)); }
return(
$item);
}
?>

From a WTF to an OMG WTF! Fixer functions are so damn wrong! They don't solve the original problem, they add more complexity and they make the original problem worse. They do make you look smarter though and that's what's important! Look how I solved that data ambiguity problem! Aren't I clever?

/sarcasm.

That's an ODD piece of code....

Wonky Code

Fabel sent in today's WTF. It short, and it definately made me go WTF... trying to figure out what it does. After looking at it, and looking at it a little more, it appears to check if $x is even or odd. Here's what Fabel had to say:

Heh this wasnt written by any of us in house it was from someone elses code that got used in a credit card validation routine, i noticed it one day and literally went WTF i've never seen anyone use this method to see if a number is odd or not. I had to do a double take to realize what it was checking for im used to seeing either a modulus to check or just a if($x & 1) for checking an odd number.

<?php
if ($x/2 != floor($x/2)) {
  
$digit *= 2;
}
?>