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)&&(!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.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

gah former programmers at my current job pulled the exact same crap. In php by default mysql_fetch_array returns an array AND an associative array. They tried to abstract it out and as a result create a db abstraction that will never be portable to another db.

He's so smart that he wrote two functions to cancel each other out. =D

the fixate() function is useless: see the PHP Manual about "Type Juggling" / type casting

var_dump(fixate(123) === (array)123);

well ... was there any special reason to call this "I'm smrt" ? in my language, "smrt" means "death" so ... well ... i was just wondering :)

nothing personal, but your "oh i'm sooo smart and boast with it, and teach everyone to code the \"right\" way" comment style really sucks balls.
the funny sarcastic style in thedailywtf makes it worth-a-while read every morning, but sorry, seems you haven't got the touch.
pity :(

Matejcik,

I believe the SMRT title is a reference to The Simpsons. In one episode, Homer is proud of himself and sings "I am so smart, I am so smart, s-m-r-t....I mean s-m-A-r-t".

Nice language you guys are using, is this typical at the meetings? Maybe I should go to the Cold Fusion Group's meetings instead?

Anything written in PHP would qualify for this site. PHP is such a poor "programming language" made popular by script kiddies and the opensource losers.

funny stuff. To the author: keep it up, it's amusing.

to the readers: it's also funny how many morons posted comments. morons, it's funny. the site is funny. its WRITTEN to be FUNNY. dont slander the language just cause you dont like it! Personally, I'm not a fan of coldfusion... you dont see me going around saying "cf sucks. tag based style is gonna die". WHen i state a point I actually have information to ground my argument.

Grow up.

Dude, all the guy is asking, is if you guys always talk like that, and if you do, he's going to go somewhere else. He didn't bash PHP or anything. Just asked a simple question and you jump all over the guy.

Grow up yourself.

he didnt ask a question. he blatently said "php is a poor 'programming language'". right there above my comment, buddy. can ya read?

I've done that too and it w

I've done that too and it was fine. Of course, I sent a parameter called $onerow if I only wanted the first row.

Post new comment




*

  • Web and e-mail addresses are automatically converted into links.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <br /> <br>