View Full Version : Question: About performance OOP/non-OOP

04-15-2012, 03:07 PM
Well I was wondering is it really faster to use OOP. For example is it faster when creating a new user and write everything all his personal information like address in the database when using OOP. Or isn't it. Since I am pretty new to OOP stuff, I can't really understand that it is faster.

04-15-2012, 05:27 PM
OOP isn't faster nor do I think anyone ever claimed it was a faster method to process, the difference more times than not is measured in milliseconds so typically it wouldn't matter, OOP is slightly slower than procedural code.

The reason to use object oriented programming is because the code is reusable hence saves you, the coder, time and can build an application in minutes that would normally take an hour rewriting same old code. For a few throw away projects I used procedural and it was just a mistake, making anything indepth becomes hardly possible to manage, if there's a bug you'll spend hours trying to find in which file and why where as with OOP you know what method is handling what logic and can fix any issues on the fly.

04-15-2012, 06:07 PM
So if I am correct, OOP is slightly slower but nearly not measurable. It saves time writing, easier to fix bugs.

Thank you that was the thing I was looking for. I am sure I'll continue with doing it OOP then.

04-15-2012, 06:59 PM
[Almost]Anything you do in OOP will be faster and require less code to do in Procedural. Almost.
But OOP gains three main advantages over procedural. First is that its reusable so long as it was written generically (otherwise minor modifications would be required). Second its centralized so "fixing" or modifying is always in a single location. Finally, it has a certain degree of privacy control between objects that's very difficult to simulate properly in procedural code. Inheritance and typehint logic is also difficult to simulate in procedural, though not impossible (except that its not inheritance anymore, rather a derivative of it since inheritance is part of the OO paradigm).

So for a rule of thumb. If you want less code that runs faster use procedural. If you want reusable code with greater control use OO.

04-17-2012, 06:33 PM
I understand to benefits of OO against procedural. Learning it is much harder then learning coding procedural I already experience that. But if I read your guys opinions and others. I see OO has more pros than cons so, I won't quit learning and practising it.

04-17-2012, 07:34 PM
I understand to benefits of OO against procedural. Learning it is much harder then learning coding procedural I already experience that. But if I read your guys opinions and others. I see OO has more pros than cons so, I won't quit learning and practising it.

Yep. I'd reserve procedural for something like embedded systems programming when resources are really tight. I don't suggest just throwing away resources, but with how much we have nowadays I'd suggest that the loss of resource for the gain of OOP seems to be a fair trade.
I believe that PHP alone has upped its default memory consumption to 128MB, I'd expect 6.x will be higher yet. I've never near approached that much memory, but once I wrote something that nearly consumed the entire 8MB available at the time.
Good o'l days of 32MB ram. What a great webserver that was.

04-17-2012, 08:32 PM
As far as I understand OO is great for bigger projects and procedural for small simple systems which are meant to do just one or a few actions.

Am I correct if I say OO takes a lot of preperation and less coding itself. Also less time consuming to fix bugs and upgrade your system. Compared to procedural. Saying this I am talking about bigger projects.

04-17-2012, 08:58 PM
Both require proper preparation. Design is much more important than creation.
OO will almost always take more code than procedural, which logically equates to more time coding (minus tricks like IDE accessor / mutator auto creations).
Size of the project is irrelevant IMO. I can take any simple functionality and turn it into a more complicated OO implementation. Is it better? No, it does the same thing. Is it easier to use? Maybe. Is it easier to expand? Probably.
Best example I could think of is making a composite calculator where I can keep giving it new instances of classes to add additional functionality. This is relatively easy to do in OOP, but takes more effort to do in procedural. End result of add, subtract, multiply and divide in procedural would be about 20 lines of code to deal with the lhs, rhs, and which operation to perform. Compare that to 5 OO classes plus one interface. Even though each class is a single method with a single instruction in it, the end code wise is substantially more than 20 lines of code.
The real difference is so long as I built it correctly, adding a new operation is a simple matter of:

$calculator->addOperation(new CalculateDivide());

And it will build itself according to what I have designed. In procedural, I'd have to write the switch for the operation, the HTML for the input, etc.

04-17-2012, 09:04 PM
Hmm, I see. If anyone has to say something more I would love to read it.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum