Sunday 16 December 2007

Object Oriented Programming vs. Structured Programming Paradigm

Discuss why Object Oriented Programming is considered a better choice than the structured programming paradigm. Does it reflect our "natural" way of thinking or do you find it artificial?

The most obvious reason that Object Oriented Programming (OOP) is considered a better choice is that is supposed to better represent the way that humans think about the world than the structured programming paradigm. We don't really view life as a series of instructions waiting to be processed - this is how a computer operates. Rather, we see ourselves as one of millions of objects that interact with each other, and OOP should make writing software easier because it embraces this view. At a more operational level the supremacy of OOP over procedural programming is nicely summarised by Matt Weisfeld. "Access to data is uncontrolled and unpredicable [in procedural programming] and because you have no control over who has access to the data testing and debugging are much more difficult. Objects address this problem by combining data and behaviour into a nice complete package" (2007).

I do find the OOP paradigm a rather artificial and forced way of thinking. Don't get me wrong, as someone who spends a lot of time developing code I can fully grasp the advantages of it. For example in a current project I have a class called ToolBox that contains a method called AuditLog. I can insert a line into any other method that logs whatever information I desire into a database log without having to constantly re-write (or cut and paste) the code that controls the database insert. And by making this method available in a web service anyone else with access to the same network can use it too. But I don't really think in terms of objects - I just think about what actions I need to perform inside my system and write methods accordingly. Of course if I take into account that fact that I am using objects defined by other programmers - for example, there is a class in .NET and Java called XmlDocument - and can pass these in and out of my own methods then I am probably using OOP more than I give myself credit for, but that is not intentional.

I just think that if OOP really reflected how we think about the world then it wouldn't be such a struggle to come to terms with. "Novice designs are littered with regressions to global thinking: gratuitous global variables, unnecessary pointers, and inappropriate reliance on the implementation of other objects" (Beck & Cunningham, 1989). However I wonder if this comes from the fact that todays industry - standard OOP languages (C# / Java) are still have their roots in procedural programming. I also think that because I learned to program procedurally first and then came to OOP later I find it harder to make the transition. "Indeed many people who have no training in computer science and no idea how a computer works find the object - oriented model of problem solving quite natural" (Budd, 1987).

Refs:
Weisfeld, M. (2007) Moving from Procedural to Object-Oriented Development [Online] JupiterMedia Corporation, USA
Available from http://www.developer.com/java/other/article.php/10936_3304881_2 (Accessed 16th Dec. 2007)

Beck, K. & Cunningham, W. (1989) A Laboratory for Teaching Object Oriented Thinking [Online] Sigplan Notices Vol 24 No 10
Available from http://c2.com/doc/oopsla89/paper.html (Accessed 16th Dec. 2007)

Budd, T (1987) A Little Smalltalk [Online] Pearson Education Inc.
Available from http://www.iam.unibe.ch/~ducasse/FreeBooks/LittleSmalltalk/ALittleSmalltalk.pdf (Accessed 16th Dec. 2007)

No comments: