SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Harnessing the power of OOP

    Lately, when discussing frameworks, I've been hearing a lot of people refer to some frameworks as being better because they have more advanced usage of OOP, and they "harness the power" of OOP. For me, I've always felt that OOP just helped better organize my work, especially since using a framework. What I'm curious about is if there really is any truth to there being and performance increase associated with using OOP. I'm guessing not, but it's only a guess. Where is the power that these people are harnessing?

  2. #2
    SitePoint Guru
    Join Date
    Jun 2006
    Posts
    638
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OOP will always be slower than procedural.

    The "power" with it, beside organization, is that there will be less places to add caching and so on.

    So, even if it's slower, it takes less work to optimize and make it "acceptable" when you need to fit more users on your site without getting new servers.

  3. #3
    SitePoint Enthusiast konsama's Avatar
    Join Date
    Jun 2007
    Location
    Sweden
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The PHP Anthology - OOP PHP Solutions, Volume 1 - By Harry Fuecks
    • Chapter 1: PHP Basics - Write Reusable Code, page 21


    - Some people argue that writing object oriented code in PHP slows down the application's performance and should therefore be avoided at all costs.

    - What they forget to mention is the drastic increase in your performance that object oriented programming delivers.

    - After all, fast programmers cost more than fast microprocessors!

  4. #4
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    988
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    OOP isn't always slower, due to the nature of procedural code it's often easy to miss the fact that you're doing the same thing over and over.

    There's a nice example here: http://www.sitepoint.com/blogs/2005/...d-performance/

  5. #5
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see OOP as being slow, but that is probably relative to my experience. My website for example runs on the CodeIgniter framework, and at least on my end, it seems to function as well as it should.

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2003
    Location
    norway
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing about performance is that the "new" autoload feature include a file/class only when the object is being created from the class, instead of including all the librarys files at the top of the page , as seen on some procedural sites and older php oop solutions..
    This gives less code to parse/include in some cases...

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    skunkbad, if you see OOP only as a tool to better organize your code, you're missing the point of OOP. This isn't meant as a flame at all - I used to use classes simply as containers for similar pieces of code. Once I realized what OOP was really about, it completely changed how I program (for the better). OOP will usually be slower than clean procedural code, and will often take longer to write in the beginning (if you're writing it from scratch) - however, and this is very important, you will benefit greatly by having clean, manageable, and reusable code. I can't tell you how many times I've had to work on a procedural script 6 months after first writing it and wanting to smash my head against the keyboard. If you write proper OOP, this becomes a thing of the past. Whatever framework you choose, it's important that it follows proper OOP standards.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Location
    Brisbane, Australia
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When using a high level language like PHP, the last thing you should be worry about is a performance and memory usage gains of writing procedural over object-orientated code. If code performance and memory usage were to cause an excessive overhead, you wouldn't switch from OO PHP to Procedural PHP, you would rewrite your code in a more robust language (C, Python, Java, etc).

    So basically, use OOP.


Bookmarks

Posting Permissions

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