Best code ever!.. NOT!

The company I work for has used a couple of 3rd parties to develop a some of our projects. The code you get back is usually quite bad to begin with, but yesterday I found the ultimate in bad code.

How not to code:

ActionScript

  1. switch(imageList.length){
  2. case 1:
  3. this._imageList.push(chooseType(pcurlImage1, curlImage1, typeArray[0]));
  4. rowNum = 1;
  5. break;
  6. case 2:
  7. this._imageList.push(chooseType(pcurlImage1, curlImage1, typeArray[0]));
  8. this._imageList.push(chooseType(pcurlImage6, curlImage6, typeArray[1]));
  9. rowNum = 1;
  10. break;
  11. case 3:
  12. this._imageList.push(chooseType(pcurlImage0, curlImage0, typeArray[0]));
  13. this._imageList.push(chooseType(pcurlImage3, curlImage3, typeArray[1]));
  14. this._imageList.push(chooseType(pcurlImage6, curlImage6, typeArray[2]));
  15. break;
  16. case 4:
  17. this._imageList.push(chooseType(pcurlImage1, curlImage1, typeArray[0]));
  18. this._imageList.push(chooseType(pcurlImage4, curlImage4, typeArray[1]));
  19. this._imageList.push(chooseType(pcurlImage6, curlImage6, typeArray[2]));
  20. this._imageList.push(chooseType(pcurlImage9, curlImage9, typeArray[3]));
  21. break;
  22. case 5:
  23. this._imageList.push(chooseType(pcurlImage1, curlImage1, typeArray[0]));
  24. this._imageList.push(chooseType(pcurlImage3, curlImage3, typeArray[1]));
  25. this._imageList.push(chooseType(pcurlImage5, curlImage5, typeArray[2]));
  26. this._imageList.push(chooseType(pcurlImage7, curlImage7, typeArray[3]));
  27. this._imageList.push(chooseType(pcurlImage9, curlImage9, typeArray[4]));
  28. break;
  29. case 6:
  30. this._imageList.push(chooseType(pcurlImage0, curlImage0, typeArray[0]));
  31. this._imageList.push(chooseType(pcurlImage1, curlImage1, typeArray[1]));
  32. this._imageList.push(chooseType(pcurlImage2, curlImage2, typeArray[2]));
  33. this._imageList.push(chooseType(pcurlImage5, curlImage5, typeArray[3]));
  34. this._imageList.push(chooseType(pcurlImage6, curlImage6, typeArray[4]));
  35. this._imageList.push(chooseType(pcurlImage7, curlImage7, typeArray[5]));
  36. break;
  37. case 7:
  38. this._imageList.push(chooseType(pcurlImage0, curlImage0, typeArray[0]));
  39. this._imageList.push(chooseType(pcurlImage2, curlImage2, typeArray[1]));
  40. this._imageList.push(chooseType(pcurlImage4, curlImage4, typeArray[2]));
  41. this._imageList.push(chooseType(pcurlImage5, curlImage5, typeArray[3]));
  42. this._imageList.push(chooseType(pcurlImage6, curlImage6, typeArray[4]));
  43. this._imageList.push(chooseType(pcurlImage7, curlImage7, typeArray[5]));
  44. this._imageList.push(chooseType(pcurlImage8, curlImage8, typeArray[6]));
  45. break;
  46. case 8:
  47. this._imageList.push(chooseType(pcurlImage0, curlImage0, typeArray[0]));
  48. this._imageList.push(chooseType(pcurlImage1, curlImage1, typeArray[1]));
  49. this._imageList.push(chooseType(pcurlImage2, curlImage2, typeArray[2]));
  50. this._imageList.push(chooseType(pcurlImage3, curlImage3, typeArray[3]));
  51. this._imageList.push(chooseType(pcurlImage5, curlImage5, typeArray[4]));
  52. this._imageList.push(chooseType(pcurlImage6, curlImage6, typeArray[5]));
  53. this._imageList.push(chooseType(pcurlImage7, curlImage7, typeArray[6]));
  54. this._imageList.push(chooseType(pcurlImage8, curlImage8, typeArray[7]));
  55. break;
  56. case 9:
  57. this._imageList.push(chooseType(pcurlImage0, curlImage0, typeArray[0]));
  58. this._imageList.push(chooseType(pcurlImage1, curlImage1, typeArray[1]));
  59. this._imageList.push(chooseType(pcurlImage2, curlImage2, typeArray[2]));
  60. this._imageList.push(chooseType(pcurlImage3, curlImage3, typeArray[3]));
  61. this._imageList.push(chooseType(pcurlImage4, curlImage4, typeArray[4]));
  62. this._imageList.push(chooseType(pcurlImage5, curlImage5, typeArray[5]));
  63. this._imageList.push(chooseType(pcurlImage6, curlImage6, typeArray[6]));
  64. this._imageList.push(chooseType(pcurlImage7, curlImage7, typeArray[7]));
  65. this._imageList.push(chooseType(pcurlImage8, curlImage8, typeArray[8]));
  66. break;
  67. case 10:
  68. this._imageList.push(chooseType(pcurlImage0, curlImage0, typeArray[0]));
  69. this._imageList.push(chooseType(pcurlImage1, curlImage1, typeArray[1]));
  70. this._imageList.push(chooseType(pcurlImage2, curlImage2, typeArray[2]));
  71. this._imageList.push(chooseType(pcurlImage3, curlImage3, typeArray[3]));
  72. this._imageList.push(chooseType(pcurlImage4, curlImage4, typeArray[4]));
  73. this._imageList.push(chooseType(pcurlImage5, curlImage5, typeArray[5]));
  74. this._imageList.push(chooseType(pcurlImage6, curlImage6, typeArray[6]));
  75. this._imageList.push(chooseType(pcurlImage7, curlImage7, typeArray[7]));
  76. this._imageList.push(chooseType(pcurlImage8, curlImage8, typeArray[8]));
  77. this._imageList.push(chooseType(pcurlImage9, curlImage9, typeArray[9]));
  78. break;
  79. }

2 thoughts on “Best code ever!.. NOT!

  1. This ‘code’ (I can’t really call it code) is used to display 1 to 10 thumbnails on a page. As this is a Flex project I think a simple repeater or maybe even a tile component could have done the trick.

Leave a Reply

Your email address will not be published. Required fields are marked *