Dissecting a Program
harish — Tue, 04/25/2006 - 16:00
You are given a problem statement. You need to solve the problem. Eventually you need to write a program to solve it. So how are you going to go about it? This is one question that I have been asking to myself for a long time. In order to do this, we first need to know what a program consists of. As far as a lay man goes, a program is just a set of lines of code written in a programming language. But I say it's more than just lines of code. Its poetry altogether (at least the essence of it is).
On reading the problem statement, we get to know what we have to do. From what we have to do, we also get to know what more we have to do. In general there is a tendency where people figure out what to do and miss out what more they have to do. I also belong to this particular category. The more part is almost always important only if the program is being written for the software industry. I'll come back to this later.
So now we know what to do. Next step is how we are going to go about it. Before we can start writing the program, we first need the Algorithm for the problem. I find many who are confused with the notion of Algorithm and program, and use one term for the other. The two terms are by no way similar. To put it in simple terms, an Algorithm just says how you do something, while a program is actually doing it. Writing an algorithm does not depend on anything. It just requires you to know what the input is and what the output is supposed to be. While the program for that algorithm depends on a lot of factors which includes the programming language used as the main factor (it takes up 90% of the pie).
Designing the Algorithm for a problem is the toughest part of the solution. It is not that given an algorithm, then writing the code for it is easy, it is just that it is only easier than designing the algorithm. Hence it is always a good practice to design the complete algorithm of the problem before one starts coding. As I have said earlier, an algorithm is just a set of steps to be followed in order to solve the problem.
The Algorithm is now ready. It is now the time to open up you favorite editors to type the program in the language of your choice. Let me call this exercise as coding. One thing that should be taken care while coding is to make sure that you exactly do what your algorithm tells you to do. How ever optimal your algorithm might be, a bad code can make your algorithm look ugly.
Now to the most important part if you are a software engineer, the what more part I was talking about. It comes in handy only when the users of your program don’t know how to use it. It has been really unfortunate to notice that many in the industry concentrate on this rather than the algorithm. But fortunately for them because of this their revenue is increasing.
Which is tougher
Rajesh Goli (not verified) — Wed, 04/26/2006 - 11:08I think people consider the "what more to do" part to be harder than "what to do" or "algorithm" part. You know I am telling this from experience..