Saturday, 6 April 2013

Spaghetti is tempting, but it's better to stay away from it

Before you start thinking that I am going to give you some advice on health, don't worry I am not.


As tempting it may seem, it's bad when you write it. I mean writing 'Spaghetti Code' is bad for your code, and bad for your health.

So what is spaghetti code?

Imagine, that you start working on some GUI app, you write the GUI code and the controller code together.
You are banging the keyboard and hacking the code together thinking "MAN, I m GONNA FINISH IT TONIGHT'  all your methods are working , all exceptions have been handled and you are ready to ship the app by next morning...



FEELING PROUD??

Well you should be... you shipped an app by hacking the View and Controller together. You wrote a ton of  "Spaghetti Code" and completed work in a few hours time, so why the Title?
 After a few months.....

Your issue tracker has some issues and you plan to sit down on the project to ship an update, feeling 'I AM GOING TO MAKE IT AWESOME AGAIN' you open up your IDE, open up the project and ....




You are bedazzled to see the spaghetti.....yes sir fast food is not good for health
Your code has no comments, since your controller and view are binded together reusing code is not an option, and debugging is *ahem* not easy, so what you do... you approach your codebuddy. He comes over willing to help, sees the code nearly faints your WTF's/Minute soar faster than yahoo's stock price during the dot-com bubble.Abandon the project or re-write the code.

So by now you might have understood why Spaghetti is harmful