Object Oriented or Precedural?

TopSilver

Active Coder
Community Partner
Mar 16, 2019
133
59
28
Would you rather code in object oriented or procedural. Xenforo 2 is object oriented mainly but other platforms such as wordpress or wordpress add-ons I hear are procedural. Which one do you prefer more and why? Personally I prefer object oriented using class based methods. It seems to be more interesting to me and much easier to learn in my personal opinion. Sometimes when I read books I find it hard to understand procedural methods in the way they explain the code. The syntax isn't hard but the way the code is explained as only procedural.

Yet when you dive into the code for object oriented you can basically see what's going on a lot easier. I'm not professional at either and still learning but it's more-so simpler to grasp personally for myself.

Which do you prefer?
 
  • Like
Reactions: Ghost

Ghost

Active Coder
Moderator
Apr 19, 2019
337
153
43
I prefer OOP (object orientated programming) because it just seems a lot more organized and modular because of the class system and extensions.
For example, I usually create a class called 'System' in my projects. This class connects to the database, handles error reporting & logging, and also supplies some system wide functions that are used by all the other classes.

So, I can then use the System class with others...
Example:
class User extends System{

}

This allows the User class to inherit functions/variables from System! :)

However, I also use procedural for smaller projects. Sometimes there's just no need to have an organized class system if the pages I am creating are very simple and not going to be expanded upon. If I need to write something up quickly, I'll just create a single functions file that holds them all in one place. If I need to write something REALLY quickly, I'll just write everything inline, but I hardly ever do that because 9 times out of 10 it looks disorganized and results in more code because you can't reuse things. So, if you're coding in almost any language and you have to choose OOP or Procedural, at least do one of them instead of creating spaghetti code with no defined functions/methods/classes. They're both better than nothing, but personally I use OOP around 90% of the time these days.
 
  • Like
Reactions: William

sn0w

Coder
Jun 6, 2019
42
19
8
[DATA EXPUNGED]
For me it really depends on how performance-critical the code in question is.
Especially in the context of PHP and other CGI webapps, you have to keep in mind that all your code runs every time on each request.
With huge frameworks like Symfony that means constructing thousands of class instances on each request, which might exhaust your memory and/or CPU sooner.
 

William

Active Coder
Sep 7, 2019
178
32
38
Well, I don't really have a preference much to say the least.

I quite like both ways of Programming but that's just as of now and I've yet to change as I start to learn more Programming-Languages and further study Computer-Science. C which is my new favourite Language is a Procedural-Language. So, there are no Classes. Now, I'm not good with Classes and so I plan to further study them when I get a new Java Book. So, that's why I quite like Procedural. Instead in C, we use Functions(Or 'Methods' as they're called in Object-Oriented[I'm pretty sure anyway. Again, I've yet to further study them]).

As for Object-Oriented, I don't really have a solid opinion on it, just like Procedural-Programming. What I don't like is Classes, Interfaces and Inheritance. Maybe that's because I don't know much about them yet and have still to continue learning them as that more than likely, is the case. But, I do happen to like Java and that is Object-Oriented. I have also picked up a tiny bit of interest in Ruby. That's also Object-Oriented. Python I know a bit about but it's not my cup of tea. That's also Object-Oriented. Again, it's things like Classes and Inheritance that I just don't happen to get which is why I don't have a solid opinion on Object-Oriented.

As of now, again, I've yet to further learn about Programming-Paradigms. Then once I learn a bit more about them, I learn about Classes and Inheritance and all of that, then maybe I'll have a preference for a Paradigm.