Jump to content
MakeWebGames

Why are you still using procedural code?


LordDan

Recommended Posts

I wish to hear peoples reasoning for staying with procedural for all this time. When I first joined this forum, I was still using procedural too, but I've 'progressed' if you will, into OO, MVC and I truly enjoy working with it. I seem to shudder looking back at procedural code, particularly when I see large chunks of HTML mixed in with PHP, or lack of comments, lack of consistency and convention. It truly annoys me and I've struggled to go back to procedural, even for tiny projects where it makes more sense.

So, a genuine question, why are you all seemingly sticking with it? Surely this goes deeper than the common excuse of "Performance" right? As snobby as I may sound here, I ask with good intent, I'm currently building up a Game Framework using OO and MVC, strictly sticking to conventions and so on etc etc. So far I have good progress, every feature is a self contained module, allowing features to be disabled, removed and installed easily with the bonus of creating hybrid genres by mixing modules. This works great, and creating a Module called Signup will override the default Signup controller, should you wish to extends it's functionality without editing the core application. Much of the code is reused from objects I have already created and I have a lot of work done already in such a small amount of time.

However, if you're still so passionate about procedural, I'm likely wasting my time marketing it here in the future when it is ready. So, I'd really enjoy your thoughts and reasoning for staying with procedural for so long.

Regards

Dan

Link to comment
Share on other sites

I personally have troubles with the OO implementation in PHP. I really don't like it. Being because it's messy, being because on each new release of PHP they change a bit the direction of it, being because many function are basically procedural and not enclosed inside a good OO structure. Compare PHP with Java or C# and you will see immediately how badly PHP implements OO.

That being said, a good code could profit from a good structure, and OO helps keep a good structure. Therefore I would also tend to say, a good OO design would be the way to go.

Yet if you talk about MVC, honestly I think this design pattern is now used like Web 2.0, or HTML 5, or many other "marketing words": just marketing. Why? Because most of the time you don't need MVC, and you actually can't really code it well either in PHP. MVC requires a full separation of the 3 areas: Model View and Controller. Where the model doesn't know anything about the 2 others, sames applies for the 2 others as well. So how should a true MVC work? Well that depends on the language you use, but ideally via events, when you modify the model, the view get waked up and should do its magic for example. In PHP what I saw most of the time is not called MVC in reality, and doesn't actually offer much more than a templating system.

I'm however in favor of the separation of the HTML and the code for the good reason that if you don't do it at start you will quiet certainly end up having nearly a fixed HTML without much options to change it, and it will make your code somewhat of a mess due to the generation of the HTML.

Link to comment
Share on other sites

You’ll find this kind of question, especially when it comes to PHP, all over the web. From a practical point of view you should be able to produce both procedural, and OO code if you’re taking any PHP jobs since its one thing a lot of people ask about. For your own programs however it’s down to personal opinion.

For MVC you might want to give this a quick look - http://makewebgames.io/showthread.php/43178-MVC-or-not-MVC

As A_Bertrand has already said OO inside PHP will seem odd if you’ve ever programmed in Java, c# or anything similar. The problem PHP currently has is a large split between those that want everyone to do everything OO and those who feel it’s not needed because PHP is not an OO language. It nearly always brings out mixed views, and heated discussions.

It’s more than possible to create good code structure with Procedural, and fairly easy to maintain well built software despite the ultra-pro OO groups wanting you to think once you’ve written anything in PHP it suddenly becomes impossible to maintain. If your older code is unworkable, even by yourself, you have to ask if it’s because it’s not OO or because you didn’t create it with any kind of structure.

You asked about why we still use Procedural code ourselves, and for me it’s not that simple. I use OOP in some projects, and in some I don’t. I honestly feel like you should decide what the program is doing then pick how you create it. Locking yourself into always using OOP, always creating the program with an MVC structure, limits you as much if not more so then not knowing how to program that way at all.

Edited by Dominion
Link to comment
Share on other sites

  • 2 weeks later...

Interesting thoughts.

I recently upgraded my development machine and whilst backing up my projects I stumbled across my very first, from scratch PHP project. It was looking through that old code from 2005/06 that got me to thinking of Procedural again. Admittedly, this was back when it was possible to waste a day away developing and enjoying every second of it. Being able to just make **** work whether it conformed to some sort of convention, or having your code perceived as poor quality because it isn't "pro-something" or "anti-some-other-crap".

I miss these times.

Link to comment
Share on other sites

I use both, when working with Wordpress I use Procedural. General rule I use is, if the product you are working with is in OO when use OO if its procedural when use that.

Link to comment
Share on other sites

I use both, when working with Wordpress I use Procedural. General rule I use is, if the product you are working with is in OO when use OO if its procedural when use that.

Wordpress isn't procedural.

And to correct your statement:

"I use both, when working with Wordpress I program procedurally. A general rule I use is: if the product you are working with is written as OO then use OOP, or else recode that ****.

Link to comment
Share on other sites

Wordpress isn't procedural.

And to correct your statement:

"I use both, when working with Wordpress I program procedurally. A general rule I use is: if the product you are working with is written as OO then use OOP, or else recode that ****.

I would class Wordpress as being procedural, how would you class that as OO? If I want my statements correcting i'll ask otherwise I don't care.

Edited by Guest
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...