Charl van Niekerk » Blog

Main

Latest

Archives

Powered by Blogger

Warcode

I was out most of the day but when I got back I saw Jonathan Endersby's post Codewar on the Clug Park I was almost outraged as I knew here goes a perfectly good 30 mins I'll never see again. However, it ended up being more than worth-while just in terms of fun. :)

However, awesome code there is not much of. However, what there is much of, especially in the PHP world, is absolutely horrible code. I didn't feel up to the challenge of writing nice code so I thought I would add to the scandal instead, which was definitely not very difficult (it's PHP after all):

<?php
$a = array();
for ($i = 0; $i < 6; $i++) {
  while (in_array($x = mt_rand(1, 10), $a) || !($a[] = $x)) {}
  echo "$a[$i] ";
}

Actually I can't even blame PHP here. This is just out-right disgusting.

Who on earth can read this now? It looks like it's been written by a retard. I should be ashamed! Especially after doing all that work in a conditional statement. What blatant abuse of a computer language! If this was a human language, they would have banned me off the internet due to pushing foul language to a new all-time low.

As Jonathan Hitchcock could rightly point out, this could loop forever. However I do believe that mt_rand is substantially better then the "usual" rand. After all, if you want to write freakish code, might as well do it properly.

Good challenge! Keep them coming! :)

0 Comments

Post a Comment

Copyright © 2004-2009 Charl van Niekerk. All articles are released under the Creative Commons Attribution 2.5 South Africa licence, unless where otherwise stated.