
Writing programs - object-oriented or structured?
When writing coursework programs we often have to advise the client whether the program should be written in an object-oriented or a structured way. Of course, what matters most in this case is how you were taught to program in the classes for which the ordered program is to be produced...That is why it is really you who should tell us how the coursework program we are to write for you should be written. Since this is very important, we advise you to make sure of it, because a wrong decision on this point may result in a failing grade for the course.
However, if the lecturer leaves students a free hand on this point, then, frankly, the answer can be reduced to one word - object-oriented - but let's start at the beginning, with definitions:
Structured programming is an extension of the concept of procedural programming, so it is a methodology of writing programs based on the hierarchical division of code into modules that communicate with each other through strictly defined interfaces. Data, procedures and functions are not directly linked to one another, and instructions are executed sequentially. The foundation of structured programming is conditional statements and loops, whereas all kinds of jumps are regarded as bad manners - remnants of linear programming which are (and rightly so) considered something that spoils the readability of source code and makes it harder to analyse.
Object-oriented programming, on the other hand, is a methodology for writing computer programs which defines programs using objects that combine the data and behaviour of the program (defined as procedures and functions, which in object-oriented programming are called methods). A program is expressed as the sum of such objects, which communicate with each other in order to carry out the tasks set for the program. This makes it possible to write large projects efficiently by teams of programmers, by assembling them from mutually cooperating objects responsible for individual elements of the software.
That's enough about objective definitions - now it is time for (no doubt entirely unobjective) opinions. In my view, although object-oriented programming imposes a certain regime and constraints that often discourage young adepts of the art of programming from learning it, spending a little time getting to know the principles of object-oriented programming brings undeniable benefits.
The possibilities arising from the object-oriented approach to data, and from object-oriented writing of programs by entire teams of programmers, seem extremely important. These are people who in the real world often don't even know each other, yet together build huge applications, communicating with one another using nothing more than descriptions of the interfaces of a class's methods, without any need to look inside. Another advantage of object-oriented programming is that the code is readable and clear: one glance at the definition file is enough, and after a moment we know what a given class or method is responsible for,
The situation is quite different with structured programming. First of all, it is extremely hard to achieve readable code in larger applications. Second, once written, the code is not suitable for reuse, because adapting it to other uses usually involves a great many corrections in many different places. For this reason a program written in a structured way is rather unlikely to be reused - a programmer usually needs less time to write a new class from scratch than to keep messing about endlessly with old code.
Despite these obvious facts, our universities far more often teach structured programming, and it is coursework programs written that way which students are expected to hand in. Of course this does not apply to computer science courses, where object-oriented programming is already the standard, but on courses not directly related to computer science it is still a rarity.
In closing this article, I hope that the few words I have written will persuade you to learn object-oriented programming. I have no illusions that I have exhausted the subject - I have only touched on some of the issues and described just a small part of the advantages of object-oriented programming. There are many more, which you will discover when working on specific tasks (especially if you have to work in groups).