Jump to content
  • Advertisement
Sign in to follow this  
Acar

Is there any reason to prefer procedural programming over OOP

This topic is 848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For quite some time I've been wondering if procedural programming has any advantages over OOP or if it's just personal preference. In which situations should I prefer the procedural style if there're any?

 

Edit: Deleted the poor example.

Edited by AcarX

Share this post


Link to post
Share on other sites
Advertisement
Seems like a bad example. I wouldn't use either style, if all you're doing is assigning 5 to an integer. Edited by Nypyren

Share this post


Link to post
Share on other sites

Sorry for the poor example. What I wanted to represent is that I have some data and a set of functions which operate on them.

Edited by AcarX

Share this post


Link to post
Share on other sites

Your examples aren't really procedural vs OOP. Also your first example does dynamic memory allocation while your second doesn't and honestly looks weird to me. It's hard to say something sensible about the pros and cons with short snippets of code. Here's Brian Will's channel where he rewrites reasonably sized programs from OOP to a procedural style. I'm not aware of anyone who does the opposite so it's one sided, but you can find some takeaways in there.

 

I'm actually running an experiment myself where I take on a more C style approach to programming and I have to say I'm very much liking it so far. I made a journal entry about it a while ago. One of the biggest advantages that I've personally noticed is that procedural code is much easier to read, but I'll get back on that once I'm further ahead in my journey.

Share this post


Link to post
Share on other sites

I'm constantly moving away from OOP over the years. The idea of inheritance never made much sense to me - it just complicates things and forces you to make decissions about software design. To me that's just blah blah and i prefer to spend this time on solving real problems.

 

So i ended up using C with classes style, but i moved away from that too, mainly because of this:

 

Class member functions hide some of the data they use because you don't know what member variables they access without looking at the implementation.

This way it's hard to see data complexity, which is important to optimizing / refactoring.

Often i ended up making member functions static, forcing me to add all data to the function parameters - just to see how many there are (ALWAYS more than you would expect).

 

Next i realized that static member functions can be used from anywhere, how practical.

So why did i still using classes?

My answer was simply: To group related functions together by 'topic', so i cand find them somehow.

 

But there is something better to do this: Namespaces.

With namespaces it's possible to group stuff in hirarchies without any restrictions or problems known from inheritance.

 

Today i create a classes very rarely, using them only as an interface to a large system which is implemented mostly procedural under the hood.

But i still use a lot of small structs with member functions for trivial functionality like indexing arrays or un/packing.

Share this post


Link to post
Share on other sites

I am the same as JoeJ, I now prefer procedural and also functional (Not the same thing), I feel I get more reuse and easier composition

 

In the end it does not matter if you use OO, procedural or functional, a good design is a good design. So use whatever works for you, or better still use the one that best fits your needs :)

Share this post


Link to post
Share on other sites

 

For quite some time I've been wondering if procedural programming has any advantages over OOP or if it's just personal preference. For example:

 

Your example isn't actually procedural programming at all.  Instead it's an attempt to mimic the look of a C++ class in C-style code, but without any of the benefits that actually using a C++ class brings.  This isn't actually something you would do; procedural programming is a very different paradigm.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!