Object-Oriented Programming(OOP) uses "Objects" – data structures consisting of datafields and methods – and their interactions to design applications and computer programs. Programming techniques may include features such as Information Hiding, Data Abstraction, Encapsulation, Modularity, Polymorphism, and Inheritance. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP.
One of the principal advantages of object-oriented programming techniques over procedural programming techniques is that they enable programmers to create modules that do not need to be changed when a new type of object is added. A programmer can simply create a new object that inherits many of its features from existing objects. This makes object-oriented programs easier to modify.
The methodology focuses on data rather than processes, with programs composed of self-sufficient modules (objects) each containing all the information needed to manipulate its own data structure. This is in contrast to the existing modular programming which had been dominant for many years that focused on the function of a module, rather than specifically the data, but equally provided for code reuse, and self-sufficient reusable units of programming logic, enabling collaboration through the use of linked modules (subroutines). This more conventional approach, which still persists, tends to consider data and behavior separately.
An object-oriented program may thus be viewed as a collection of cooperating objects, as opposed to the conventional model, in which a program is seen as a list of tasks (subroutines) to perform.
OOP can be used to translate from real-world phenomena to program elements (and vice versa). OOP was even invented for the purpose of physical modeling in the Simula-67 programming language. However, not everyone agrees that direct real-world mapping is facilitated by OOP, or is even a worthy goal; Bertrand Meyer argues in Object-Oriented Software Construction that a program is not a model of the world but a model of some part of the world; "Reality is a cousin twice removed". At the same time, some principal limitations of OOP had been noted.
However, Niklaus Wirth said of OOP in his paper "Good Ideas through the Looking Glass", "This paradigm closely reflects the structure of systems 'in the real world', and it is therefore well suited to model complex systems with complex behaviours.
Thursday, August 20, 2009
Thursday, July 30, 2009
Structured Programming - Little Introduction
Structured Programming (sometimes known as Modular Programming) is a subset of Procedural Programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify.
Structured programming was first suggested by Corrado Bohm and Guiseppe Jacopini. The two mathematicians demonstrated that any computer program can be written with just three structures: Decisions, Sequences and Loops.
1) In "Decision" one of a number of statements is executed depending on the state of the program. This is usually expressed with keywords such as if..then..else..endif, switch, or case.
2) "Sequence" refers to an ordered execution of statements.
3) In "Loop" a statement is executed until the program reaches a certain state or operations are applied to every element of a collection. This is usually expressed with keywords such as while, repeat, for or do..until. Often it is recommended that each loop should only have one entry point (and in the original structural programming, also only one exit point), and a few languages enforce this.
Structured programming frequently (but not always) employs a top-down design model, in which developers map out the overall program structure into separate subsections. A defined function or set of similar functions is coded in a separate module or submodule, which means that code can be loaded into memory more efficiently and that modules can be reused in other programs. After a module has been tested individually, it is then integrated with other modules into the overall program structure.
It is possible to do structured programming in almost any procedural programming language, but since about 1970 when structured programming began to gain popularity as a technique, most new procedural programming languages have included features to encourage structured programming, (and sometimes have left out features that would make unstructured programming easy). Some of famous structured languages are ALGOL, PASCAL, Ada, C etc.
Coders should break larger pieces of code into shorter subroutines (functions and procedures in some languages) that are small enough to be understood easily. In general, programs should use global variables sparingly; instead, subroutines should use local variables and take arguments by either value or reference. These techniques help to make isolated small pieces of code easier to understand without having to understand the whole program at once.
Strictly speaking, in a structured programming language, any code structure should have only one entry point and one point of exit; many languages such as C allow multiple paths to a structure's exit (such as "continue", "break", and "return"), which can bring both advantages and disadvantages in readability.
So, Happy Programming.....
Structured programming was first suggested by Corrado Bohm and Guiseppe Jacopini. The two mathematicians demonstrated that any computer program can be written with just three structures: Decisions, Sequences and Loops.
1) In "Decision" one of a number of statements is executed depending on the state of the program. This is usually expressed with keywords such as if..then..else..endif, switch, or case.
2) "Sequence" refers to an ordered execution of statements.
3) In "Loop" a statement is executed until the program reaches a certain state or operations are applied to every element of a collection. This is usually expressed with keywords such as while, repeat, for or do..until. Often it is recommended that each loop should only have one entry point (and in the original structural programming, also only one exit point), and a few languages enforce this.
Structured programming frequently (but not always) employs a top-down design model, in which developers map out the overall program structure into separate subsections. A defined function or set of similar functions is coded in a separate module or submodule, which means that code can be loaded into memory more efficiently and that modules can be reused in other programs. After a module has been tested individually, it is then integrated with other modules into the overall program structure.
It is possible to do structured programming in almost any procedural programming language, but since about 1970 when structured programming began to gain popularity as a technique, most new procedural programming languages have included features to encourage structured programming, (and sometimes have left out features that would make unstructured programming easy). Some of famous structured languages are ALGOL, PASCAL, Ada, C etc.
Coders should break larger pieces of code into shorter subroutines (functions and procedures in some languages) that are small enough to be understood easily. In general, programs should use global variables sparingly; instead, subroutines should use local variables and take arguments by either value or reference. These techniques help to make isolated small pieces of code easier to understand without having to understand the whole program at once.
Strictly speaking, in a structured programming language, any code structure should have only one entry point and one point of exit; many languages such as C allow multiple paths to a structure's exit (such as "continue", "break", and "return"), which can bring both advantages and disadvantages in readability.
So, Happy Programming.....
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...
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...
So, Intro first...
Well, Myself Sanjeet Kumar, and I have written few posts on another blog of mine which contains a bit sentimental posts. But this blog will not make you upset with those kind of posts. This time I have a new idea and that is of "Posts related to technology." I think this idea will help some of you and some will get annoyed also. But I think my motive of sharing my little knowledge will get fulfilled by this. So the only line I can say now is "Happy sharing".
Subscribe to:
Comments (Atom)