PHP Classes

Procedural vs OOP analysis does not involve 'Classes' Concept

Recommend this page to a friend!

      PHP Classes blog  >  Why is it better to d...  >  All threads  >  Procedural vs OOP analysis does not...  >  (Un) Subscribe thread alerts  
Subject:Procedural vs OOP analysis does not...
Summary:... and 'Performance' is not an issue in both
Author:Rui Cunha
Date:2012-03-21 19:47:04
Update:2012-03-22 03:37:05

  1. Procedural vs OOP analysis does not...   Reply   Report abuse  
Rui Cunha - 2012-03-21 20:35:15
Definition of 'class':
- a block of code that has been designed to be reused on a sistematic basis. It receives pre-defined parameters, processes them and sends back a result for those parameters. Such result may be a value, a behaviour or something else. It does not need to be OOP or Procedural and with a properly coded algorithm performance is unlikely to be an issue in both cases.

Definition of 'Object Orient Programming':
- An alternative and more recent method of writting code that consists upon building and in someway manipulating an abstraction called 'Object'. Such objects can be used in very different ways, but some people say that the real strenght of OOP is about taking the most of the capacity that makes the best developers stand out: the hability to abstract. The code becomes more readable, concepts become more clear, and everything gets more systemic. It is an alternative to the tradicional style of writting code, that we now call 'Procedural'.

I have developed lots of classes, and used a few others. For example, I have an online platform that uses an OOP class for generating PDF's. It's called FPDF and it gets used intensively 24/7. Performace has never been an issue. If fact, it never had any issue and it has proven to be a great way to generate my pdf's.
On the ohter hand, the same same platform runs intensively all the other classes that I have written in procedural style. Some of these classes run on every single script that gets called by any user. Again, performance has never been an issue.

I'm not a fan of the OOP approach. I'm doing fine with the procedural style and I'm not planning to move on.
But keep in mind that I am also very unlikely to be considered one of those that has or will ever stand out...

  2. Re: Procedural vs OOP analysis does not...   Reply   Report abuse  
Manuel Lemos - 2012-03-21 23:04:04 - In reply to message 1 from Rui Cunha
PHP allows both OOP and non-OOP programming styles. You can use both and that is OK.

The point of the article is that if you want to organize better your code, avoiding global name collision and promoting reuse of code that can be useful in different projects, classes are the way to go.

If you do not need to make your code more organized or more reusable, you do not have to waste your time migrating code. To be clear, the article never said or suggested that you do that, so you are fine.

  3. Re: Procedural vs OOP analysis does not...   Reply   Report abuse  
José Antonio Nóbile R. - 2012-03-22 03:37:05 - In reply to message 1 from Rui Cunha
The FPDF Class is the class less usable. DOMPDF is all.

Can you show me the memory and CPU usage of generate a complex PDF with OO vs procedural style?

The time measured with 'time' command of linux. Memory can use memory_get_peak_usage(true) of PHP.

I'm sure that process of complex code is too slow that procedural code.