Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question: About performance OOP/non-OOP

    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.

  • #2
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    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.
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    [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.

  • #5
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by Krentenbol View Post
    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.

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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:
    PHP Code:
    $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.

  • #9
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hmm, I see. If anyone has to say something more I would love to read it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •