October 2004
Mon Tue Wed Thu Fri Sat Sun
<<  <   >  >>
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31


powered by

Valid XHTML 1.0!


01:24:20 pm, Categories: Bad Architecture, 242 words  

I'm smrt.

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

/* 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!

function fixate($item) {
 if (($item)&&(!is_array($item))){ return(array(0=>$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?



09:16:31 pm, Categories: Wonky Code, 137 words  

That's an ODD piece of 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.

if ($x/2 != floor($x/2)) {
  $digit *= 2;


03:06:07 pm, Categories: Bad Architecture, 174 words  

Why use MD5 when you got MD4?

Okay before we get deeper into this craziness I would like to remind people that MD5() has been available since php3. Plus MD5 is way more secure than MD4... so I introduce you to today's PHP WTF.

  function getMd4Pwd($pwd) {
    $pwd = trim($pwd);
    if (strlen($pwd) <= 0)
      return "";
    $strCmd = "/usr/local/bin/md4sum ".$pwd;
    return strtoupper($arrOut[0]);

But wait! It gets worse... not only are they not using md5(), they execute a shell script to get an MD4 hash! Really you can't make this stuff up...

And what is /usr/local/bin/md4sum you may ask? Well let me show you...

#!/usr/bin/perl -w
use Digest::MD4;
use Unicode::String qw( utf8 );
Unicode::String->stringify_as( "utf16" );
$u8 = utf8( shift );
print Digest::MD4->hexhash($u8->byteswap), "\n";

So we have a PHP script that calls a Perl script to generate an obsolete, insecure MD4 hash. Not only that but Perl doesn't even have MD4 by default, you have explicitly install it. Um...WTF?!


12:09:55 pm, Categories: Bad Architecture, 124 words  

Not so Source Control...

There is an interesting post on the The Daily WTF about Source Control, or the lack of it.

I wanted to share this. The previous developers didn't use any source control, they simply did the same thing by renaming the old files and added new ones. The file names have been changed to protect the guilty:

This WTF is completely a human problem. Given a bad situation people (especially bad programmers) will find the ways to make it worse. The problem gets worse when dumb developers start using those old libraries! Now your messy directories have turned into software requirements! This may sound retarded but this has happened, and will happen!

Remember source control is to your code as accounting is to your business.


11:44:32 am, Categories: DB Hoopla, 160 words  

When Newbies Attack!

I think inexperienced web programmers all make common DB WTFs when starting out. Jim Grill sent in a prime example from a project that he inherited. I'm sure we've all seen similar code before and we've all said, "wtf?!", if not "ytf?!"

$query = 'SELECT * FROM sometable';
$result = mysql_query($query,$connection);
$count = mysql_num_rows($result);

It should be obvious what's wrong in the example. To count the number of rows all data is needlessly requested and the rows counted in PHP. As the table grows these three lines will get slower and slower. Most people take data transfer from the DB server for granted. However we always should be as efficient as possible, since little things can quickly multiply into big problems.

The fix is relatively simple:

$query = 'SELECT COUNT(*) FROM sometable';
$result = mysql_query($query,$connection);
list($count) = mysql_fetch_array($result);

Using count(*) will return just the number of rows. Much more efficient.

:: Next Page >>