Thursday, May 14, 2009

Different types of programming...

Before talking so much about any specific programing language or a programming standard, I would like to draw your attention towards some known and unknown styles of programming. Most of us have been tried our hands on some of programming languages but the road doesn't end here.

So stepping towards a discussion about few programming types or say programming styles...

There are many programming languages. The difference between these programming languages is not just because of syntax of the language, but also because of the style of the programming in that language. An obvious example, which comes in mind is of C and C++. Both follow almost the same syntax but the style of programming is very different.

Each programming language has its own style and this is what appealed me to think about the pros and cons of different programming styles. A lot of books are available to provide detail about this topic. That's why I don't want to go into more complexities of the topic, but I would like to give you my views on it.

Let me first start with my favorite style, which I have been following almost from the time I learnt of it (My school time) - Structured Programming. As far as I know this style of programming evolved to improve the understandability of programs. as the name suggests, a program written in this manner follows a structured flow. By this statement, what I want to convey is that the flow of the program can be easily understood. Strictly speaking, this style can be followed in every programming language, except of course machine code. If you don't believe me, I still (by mistake or in hurry) follow structured approach when I code even in Java. The essence of this style which I follow is to have a single flow through the program. Every point in the program must have only one entry point and one exit point. Using this way, following a code is very easy, and can help greatly in understanding and debugging the code.

Then comes Object Oriented Programming style. This considers the whole world as objects and relations between them. This style helps in simulation of real life situations easily and is also easy to comprehend.

Then comes the Logic Programming. This basically divides the known problem data into a set of facts and rules, and the problem into a set of queries. The answers to the queries are based on applying different set of rules to the given facts. If I am not mistaken this is used extensively in AI applications, where it is important to make decisions based on earlier known and collected data.

Oh.... How could I forget? I should have started with this one first. But it is never too late to introduce Unstructured Programming, a style where nothing is followed. It's most commonly used in assembly language. This kind of programming is hard to write and understand, but also shows that how good you are at understanding code. If someone can understand unstructured programs easily, then I am sure they can understand any other type of program.

Last but not the least (at least the last style I know of) Functional Programming. I started with my favorite and also will end with another favorite of mine. Though I know very little of it, I have enjoyed very bit of what I have learnt and known of it. Here everything is a function, including your function arguments (this is in pure functional programming language). The power of functional programming is in the power of recursion. The way a problem can be divided into sub problems of the same type. I don't think I am qualified enough to speak about its power. I would just say it is beautiful.

There are many people who think one style of programming is better than the other. This notion is completely wrong. You must always think of the old saying - 'Use horses for the courses'. What might be the best choice for one problem may be the worst for another. Hence while programming, the paradigm that is used must be chosen carefully.

Happy programming...

No comments: