Article 2XNX CodeSOD: Head in the Tag Cloud

CodeSOD: Head in the Tag Cloud

by
snoofle
from The Daily WTF on (#2XNX)

When most folks create something, be it carved, welded or coded, they take pride in what they're creating. It's a reflection of their soul. It's personal. They care.

However, once you tell someone that their stuff will be in or on something that is someone else's responsibility (aka.: problem), they often take less care in what they're putting there.

To me, the phrase The Cloud can be safely replaced with Someone Else's Computer in every conceivable context; load-distribution; storage; file transfer; etc.

As such, all too often, when something is to be in/near/on/associated-with any-or-all-things-cloud, the folks who build it tend to do somewhat lower quality work.

Ayken recently inherited an old website that quickly turned out to be a management nightmare. Every veteran who is used to fighting such ancient demons knows that every PHP project comes with ridiculous stuff like this trim-function that was clearly written in complete ignorance of the existence of regular expressions:

<?phpfunction replaceWhiteSpace($str){ $str=str_replace(" ", '', $str); $str=str_replace(" ", '', $str); $str=str_replace(" ", '', $str); $str=str_replace(" ", '', $str); $str=str_replace("> <", '><',$str); $str=str_replace("> <", '><',$str); $str=str_replace("> <", '><',$str); $str=str_replace("> <",'><',$str); $str=str_replace("\n", '', $str); $str=str_replace("\t", '', $str); $str=str_replace("\rn", '', $str); return $str;}?>

However, even the most seasoned demonslayer would be shocked and appalled to see the function responsible for displaying those nifty, once very trendy tag clouds:

<?phpfunction taglink ($tag, $timesno){ global $CFG; if ($timesno==0) return "<a href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:green; font-size:21px; font-family:arial;\">$tag</font></a>"; else if ($timesno==1) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#0066FF; font-size:21px; font-family:arial;\">$tag</font></a>"; else if ($timesno==2) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#3399CC; font-size:19px; font-family:arial;\">$tag</font></a>"; else if ($timesno==3) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:green; font-size:19px; font-family:arial;\">$tag</font></a>"; else if ($timesno==4) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:blue; font-size:19px; font-family:arial;\">$tag</font></a>"; else if ($timesno==5) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#FF9933; font-size:18px; font-family:arial;\">$tag</font></a>"; else if ($timesno==6) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:blue; font-size:18px; font-family:arial;\">$tag</font></a>"; else if ($timesno==7) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#99CC33; font-size:17px; font-family:arial;\">$tag</font></a>"; else if ($timesno==8) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#003399; font-size:17px; font-family:arial;\">$tag</font></a>"; else if ($timesno==9) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#FF3333; font-size:17px; font-family:arial;\">$tag</font></a>"; else if ($timesno==10) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:grey; font-size:16px; font-family:arial;\">$tag</font></a>"; else if ($timesno==11) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#99CC33; font-size:16px; font-family:arial;\">$tag</font></a>"; else if ($timesno==12) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:red; font-size:15px; font-family:arial;\">$tag</font></a>"; else if ($timesno==13) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:blue; font-size:15px; font-family:arial;\">$tag</font></a>"; else if ($timesno==14) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:red; font-size:15px; font-family:arial;\">$tag</font></a>"; else if ($timesno==15) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#99CC33; font-size:15px; font-family:arial;\">$tag</font></a>"; else if ($timesno==16) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:red; font-size:15px; font-family:arial;\">$tag</font></a>"; else if ($timesno==17) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#330033; font-size:13px; font-family:arial;\">$tag</font></a>"; else if ($timesno==18) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:red; font-size:13px; font-family:arial;\">$tag</font></a>"; else if ($timesno==19) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#FF9933; font-size:13px; font-family:arial;\">$tag</font></a>"; else if ($timesno==20) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#FF9933; font-size:13px; font-family:arial;\">$tag</font></a>"; else if ($timesno==21) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:blue; font-size:13px; font-family:arial;\">$tag</font></a>"; else if ($timesno==22) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#FF9933; font-size:13px; font-family:arial;\">$tag</font></a>"; else if ($timesno==23) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#FF9933; font-size:13px; font-family:arial;\">$tag</font></a>"; else if ($timesno==24) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#99CC33; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==25) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#FF9933; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==26) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:grey; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==27) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:grey; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==28) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#99CC33; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==29) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#330033; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==30) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:grey; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==31) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#99CC33; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==32) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:grey; font-size:11px; font-family:arial;\">$tag</font></a>"; else if ($timesno==33) return "<a title=\"$tag\" href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:#FF9933; font-size:11px; font-family:arial;\">$tag</font></a>"; else return "<a href=\"".selfUrl("?p=arama&searchText=$tag")."\"><font style=\"color:green; font-size:19px; font-family:arial;\">$tag</font></a>";}?>

Each tag name is passed along with the number of times it appears on the website and the function then sizes them in inverse order. The more posts that reference the tag, the smaller it becomes. Finally, when it's used more than 33 times, it will become larger once more, but still a bit smaller than the ones used only once.

One can only assume that Lucy was in the Sky with Diamonds when the choices for the colors were made...

inedo50.png[Advertisement] BuildMaster is more than just an automation tool: it brings together the people, process, and practices that allow teams to deliver software rapidly, reliably, and responsibly. And it's incredibly easy to get started; download now and use the built-in tutorials and wizards to get your builds and/or deploys automated! TheDailyWtf?d=yIl2AUoC8zAgPAlAKNx7o4
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments