I like procedural programming

Let me start by saying I know all about Object-Oriented Programming and its benefits. This is not me dissing it or putting it down. It has its place in many of the projects that get done across the world. However, there is too much emphasis on it to the point where people feel that procedural programming is no longer functional for them anymore.

Many times I simply want to code something up and push it out to see how it does (another great aspect of PHP). In doing so I get to see what I like and dislike. There is no design planning. There is no time making sure that my methods are attached to the right objects. If I need to accomplish a task on a page a quick function will do.

But what happens on the larger projects I work on? Surely this approach can’t work. You know what? It actually does because my procedural code is so close to object-oriented anyways that most of the time all it involves to make the conversion is to wrap my functions in an object. In fact most of the time my code is a mix and match of procedural and OOP. I use a DB object to handle all my SQL needs, but it might be wrapped in a simple procedural function.

My code is easy to look at, I never get lost in it and I can always return to it and know exactly where I left off. Maybe I’m not launching missles with my code, but I like to think I do enough to know when its just fine to do some procedural programming. Don’t be so quick to jump onboard of what the experts feel is best. Most of the time you have to feel your own way around and if the best advice you get is to release early, release often, then find what method allows you to do that while still pumping out great code. Great code will always be great code.

(If you are heavy into frameworks ignore all the above and focus on your objects. And I have done many projects that are great examples of OOP, this applies more to my mini-projects.)

4 Responses

ilya / 03.11.09

“because my procedural code is so close to object-oriented anyways that most of the time all it involves to make the conversion is to wrap my functions in an object”

To me, this is utter BS, and clearly shows you don’t understand OO.

of course, if you are working alone on your project your code will make sense to you.. Duh..

Paul Scrivens / 03.11.09

Maybe I was too general here and deserved for that type of comment. Of course I can’t flip the switch on my code and it’s magically OO, but maybe you are unaware of the similarities of procedural and OO.

methods -> functions
objects -> modules
message -> argument
attribute -> variable

I don’t do garbage code and like it neat and in order and therefore many times it has more similarities to OO than what you might consider procedural. So yes, I do understand OO and I understand that PHP never lends itself to being a OO type of language. When doing a site in C# you get nothing but OO from me, but I know the tools I am working with and understand my final objectives.

But reading your last line I can clearly see you really have no understanding of what my point in this entry is.

ilya / 03.11.09

So i read your post again, and your comment.

Since I was maybe a bit harsh in my comment impulse…

I still think argueing that procedural and OO are very similar is not right on a number of levels. The fact that you can draw up four “elements” of the language and point out general similarities does not make up for that.

not in the least that “message passing” is actually calling a method on an object. So method and message are sort of duplicated on the left.

http://en.wikipedia.org/wiki/Object_oriented (see message passing)

the arguments passed in passing a message (or calling a method) are also referred to as arguments.

Either way, your argument that procedural languages have their merrits because they are so like OO does not cut it.

If you told me you like procedural languages because they allow you to do what you want in a neat and organized way, thats fine by me.

No one ever claimed that all software written in procedural languages are by default spaghetti code and worthless. I would make the other claim also, its entirely possible to make a huge mess in OO just the same way as one can in procedural languages.

Great code is still great code, and i agree that one should use the tools they need to get the job done right, and not jump on any bandwagon.. period.

But claiming procedural is like OO and that this makes it ok does not fly…

Paul Scrivens / 03.11.09

Whoa, whoa, I’m not saying they are the same. I was saying there many times is an over-emphasis on OO when there doesn’t need to be, but I do think you code up the same application in either methodology it simply depends on what you are going for. For reusability and making the code extendable of course you go with OO.

If they were the same then there would be no point in having separate methodologies of course.

No one ever claimed that all software written in procedural languages are by default spaghetti code and worthless. I would make the other claim also, its entirely possible to make a huge mess in OO just the same way as one can in procedural languages.

I think we are in agreement and maybe I did a poor job of getting my message across, but I can’t argue with what you have said since that is what I was trying to say.

If you told me you like procedural languages because they allow you to do what you want in a neat and organized way, thats fine by me.

That is what I said lol.

Leave a Reply