473,772 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OO in PHP

Please, someone, tell me why OO in PHP is better than procedural.
Jul 17 '05
51 5289
"Henk Verhoeven" <ne**@phppeanut sREMOVE-THIS.org> wrote in message
news:cc******** **@news2.tilbu1 .nb.home.nl...
Hi chung,

I like your reply :-)))

But OTOH i do think there is a rationale for some conformism towards
commonly accepted standards and best practices. However, OO is not
simply a "best practice" or so, imho it's a paradigm in the sense T.S.
Kuhn meant in his book "Structure of scientific revolutions". Kuhn
explained the impossability of logical or even empirical falsification
of a paradigm and described how consensus between scientists in the end
is descisive in the competition between paradigms. In that respect OO
getting into the mainstream, maybe even becoming the leading paradigm,
is the most rational measure we have of its value.

Of course this does not mean that arguments are not important, and
certainly not that discussions should stop. But it can be expected that
progress will come from NEW paradigms, not from old, predecessor ones
like procedural or structural programming.


I think it was in a Dilbert cartoon where someone invented a device which
would deliver a electric shock everytime the wearer utter terms like
"paradigm."
Jul 17 '05 #31
Mudge wrote:
Please, someone, tell me why OO in PHP is better than procedural.

Hey people. I found an article that answers my question:
http://www.zend.com/zend/art/oo-proc.php
Jul 17 '05 #32
Chung Leong wrote:
I think it was in a Dilbert cartoon where someone invented a device which
would deliver a electric shock everytime the wearer utter terms like
"paradigm."

If Dilbert had taken the specs literally, he would have invented the
machine to only give the shock if someone calls an idea, theory,
ideology or belief a paradigm. But Dilbert is an experienced developer,
he obviously knew that a version that does not make that difference will
work over 99 % correct in most circomstances, and no manager will be
able to tell the difference anyway, exept maybe for it being so much
cheaper to invent. But why tell them the device has been finished ways
before schedule if you can fill that time behind your desk with writing
profitable comics?

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

Jul 17 '05 #33
Henk Verhoeven <ne**@phppeanut sREMOVE-THIS.org> wrote in message news:<cc******* ***@news5.tilbu 1.nb.home.nl>.. .
Chung Leong wrote:
I think it was in a Dilbert cartoon where someone invented a device which
would deliver a electric shock everytime the wearer utter terms like
"paradigm."

If Dilbert had taken the specs literally, he would have invented the
machine to only give the shock if someone calls an idea, theory,
ideology or belief a paradigm. But Dilbert is an experienced developer,
he obviously knew that a version that does not make that difference will
work over 99 % correct in most circomstances, and no manager will be
able to tell the difference anyway, exept maybe for it being so much
cheaper to invent. But why tell them the device has been finished ways
before schedule if you can fill that time behind your desk with writing
profitable comics?

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.


I find it utterly frightening that you sincerely provided a complete
technical analysis of a silly one-liner. Good LORD Henk!!!!

Phil
Jul 17 '05 #34
Phil Powell wrote:

I find it utterly frightening that you sincerely provided a complete
technical analysis of a silly one-liner. Good LORD Henk!!!!

Phil


I knew it! I DO qualify for being a Software Architect! (with capitals!)

Thanks Phil!

Jul 17 '05 #35
Hello,

On 07/09/2004 06:28 PM, Henk Verhoeven wrote:
> The problem with traditional OOP is that as you evolve your library
> classes to make them more flexible, you keep adding code that will
> probably be use just in case.
Only if you never rebuild your library. I have rebuilt ours two times
now (that makes three in total). This means that after some years we
reuse the concepts and designs but drop the code. It still kept getting
more powerfull where it is most effective, but it it also gets stripped
from everything that is not the simpelest thing that could possibly work
for the most essential objectives. Therfore it's still only 1.1 Mb
uncompressed.


Refactoring does not imply code shrinking. It may happen if you focus
your efforts on that.

Still that does not avoid the problem of adding features to satisfy
better your needs. More features usually means more code.

However, different projects may use a different set of features of the
same library but each one may not use all the features. If the number of
library features used by a project is small when compared to the code
that has to be loaded, you may see the library as already bloated..
> That gets worse with cascaded dependencies: classes that get loaded just
> because you used one feature that you want from one class that requires
> other classes to implement features that you do not need.


Not if you ever only include a class if you are going to call its
functions or instantiate it.


That does not avoid what usually happens when a project just needs a
feature of a class that uses a fraction of the code, but the whole class
and any dependencies have to be loaded because the class does not have
built-in knowledge of all the features the project needs.

> It would be better if you just could tell what features you need and a
> magic generator would generate a class that includes the aspects that
> you really will use at run time.


That would only eliminate about 5 include calls from ca 3 methods per
class. I do not think that would make a big difference it the size of my
code, nor in the number of bugs. But i must admit that i use meta data
for auto inclusion in those cases where i eliminated the code it should
be in entirely ;-)


I think you need to see what exactly a smart generator does and the
difference that it makes. It takes hints specified by the developer
about the aspects that he needs to figure what code should be generated
and what is not necessary.

> You just describe your DAO classes and specify which
> functionality you need.


What else is programming? As i understand it you still need to specify,
that's source code too. I want less source code, i do nog have a
performance problem.


Sure, but since you just need to describe the model and the generator
produces the code that implements the data access class to manipulate
data according that model, rest assured that you need to write much less
code. Actually, that is the main advantage of code generation: focus
more effort on design to avoid spending too much time in implementation,
testing and debuging.
>This is an actual call for Code Generation based solutions
> like Metastorage


Why would you need a code generator for that? Why not simply factor out
the code you now generate?


Because this is a repetitive problem that that requires too much hand
coding to customize the solution according to the model.

I could build bricks manually but if I have a machine than can produce
the bricks automatically, it will certainly be more productive.

Sorry, i am just not ready to buy it that AOP would be just a perfomance
issue. To my understanding the case for AOP (and CF likewise) consists
of answers to the above question.

This does not mean that i am agains JIT compilers etc., they can be
great. I just don't think they should be a (meta)language issue.


AOP and code generation are distinct matters. AOP is about the aspects
that you may want to enable or not in your application according to your
needs. It is a matter of application customization and configuration. It
may lead to more efficient and compact applications.

If you want to debug your applications you may plug a lot of code that
implements the debugging aspects that you need. But when you ship the
application, you may want to drop all the debugging plugs to make the
application as small as it may get and eventually hide aspects that you
do not want the production users to be aware.

Code generation is about automating the generation of code to implement
repetitive code eventually following design patterns. AOP does not imply
code generation, but since often you need to process and generate code
to implement certain aspects, one thing helps the other.

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #36
Hello Manuel,

Manuel Lemos wrote:
(..)
Sure, but since you just need to describe the model and the generator
produces the code that implements the data access class to manipulate
data according that model, rest assured that you need to write much less
code. Actually, that is the main advantage of code generation: focus
more effort on design to avoid spending too much time in implementation,
testing and debuging.
I can use objects to describe the model and have them generate the
behavior i need directly. Code generation would take effort to build and
effort to maintain. It's called meta programming and though the concepts
that are implemented may be very abstract, its implementation can
usually be very simple. The only objective of code generation *may* be
performance, but why put time into that if performance problems (as far
as i have them) are not in the meta calls (call function by name etc.)?

The same holds for other performance optimalizations like the parser
having to parse more then is necessary: if the bottleneck is somewhere
else (or there is no performance problem at all), i better spend my
valuable time on other, more urent problems.
I could build bricks manually but if I have a machine than can produce
the bricks automatically, it will certainly be more productive.


It will be even more efficient if you simply skip the brick entirely ;-)

The point is, you can't convince me that code generation is better then
refactoring and meta programming IN GENERAL. I have simply seen to many
unconvincing examples. You will have to come with examples or patterns
where those simply are inadequate AND explain why that inadequacy is
inherent to refactoring, OO and meta programming, otherwise i can simply
invent a solution (and if i need it, i usually will) (or tell how the
problem was soved in Smalltalk more then a decade ago* ;-) )

I have only once read an article (from trese.cs.utwent e.nl) that
actually correctly identified limitations to the expressive power of OO
languages and explaind how they necessarily lead to repetition designs
and code, and i consider that as be a basis for extending a programming
language like PHP (with implicit delegation). I would like to read more
articles like that, but never found any. I am not interested in the many
examples that can be soved by better programming or are really just a
matter of performance optizations. The first are only making a case
against code generation (solving a problem that really isn't there is
not helping) and the last should i.m.h.o be addressed by the (JIT)
compiler, packager and VM without me as a developer having to know.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

* the problem of bloat as you descibe it was solved to a degree in most
Smalltalk dialects by the introduction of class extensions: putting
part of a class' code into a different package then where the class
itself resides. There is much design humbug with respect to C++ and Java
that is really only there becuase these languages still fail to separate
structuring for code maintenance (packages) from structuring for
execution (classes and inheritance). In this light code generations
looks to me like a poor workaround for another stubbornness of language
developers failing to address problems that where already solved in what
they are trying to mimic.

Only if you never rebuild your library. I have rebuilt ours two times
now (that makes three in total). This means that after some years we
reuse the concepts and designs but drop the code. It still kept
getting more powerfull where it is most effective, but it it also gets
stripped from everything that is not the simpelest thing that could
possibly work for the most essential objectives. Therfore it's still
only 1.1 Mb uncompressed.

Refactoring does not imply code shrinking. It may happen if you focus
your efforts on that.

Still that does not avoid the problem of adding features to satisfy
better your needs. More features usually means more code.

However, different projects may use a different set of features of the
same library but each one may not use all the features. If the number of
library features used by a project is small when compared to the code
that has to be loaded, you may see the library as already bloated..
> That gets worse with cascaded dependencies: classes that get loaded

just
> because you used one feature that you want from one class that

requires
> other classes to implement features that you do not need.


Not if you ever only include a class if you are going to call its
functions or instantiate it.

That does not avoid what usually happens when a project just needs a
feature of a class that uses a fraction of the code, but the whole class
and any dependencies have to be loaded because the class does not have
built-in knowledge of all the features the project needs.

> It would be better if you just could tell what features you need and a
> magic generator would generate a class that includes the aspects that
> you really will use at run time.


That would only eliminate about 5 include calls from ca 3 methods per
class. I do not think that would make a big difference it the size of
my code, nor in the number of bugs. But i must admit that i use meta
data for auto inclusion in those cases where i eliminated the code it
should be in entirely ;-)

I think you need to see what exactly a smart generator does and the
difference that it makes. It takes hints specified by the developer
about the aspects that he needs to figure what code should be generated
and what is not necessary.

> You just describe your DAO classes and specify which
> functionality you need.


What else is programming? As i understand it you still need to
specify, that's source code too. I want less source code, i do nog
have a performance problem.

Sure, but since you just need to describe the model and the generator
produces the code that implements the data access class to manipulate
data according that model, rest assured that you need to write much less
code. Actually, that is the main advantage of code generation: focus
more effort on design to avoid spending too much time in implementation,
testing and debuging.
>This is an actual call for Code Generation based solutions
> like Metastorage


Why would you need a code generator for that? Why not simply factor
out the code you now generate?

Because this is a repetitive problem that that requires too much hand
coding to customize the solution according to the model.

I could build bricks manually but if I have a machine than can produce
the bricks automatically, it will certainly be more productive.

Sorry, i am just not ready to buy it that AOP would be just a
perfomance issue. To my understanding the case for AOP (and CF
likewise) consists of answers to the above question.

This does not mean that i am agains JIT compilers etc., they can be
great. I just don't think they should be a (meta)language issue.

AOP and code generation are distinct matters. AOP is about the aspects
that you may want to enable or not in your application according to your
needs. It is a matter of application customization and configuration. It
may lead to more efficient and compact applications.

If you want to debug your applications you may plug a lot of code that
implements the debugging aspects that you need. But when you ship the
application, you may want to drop all the debugging plugs to make the
application as small as it may get and eventually hide aspects that you
do not want the production users to be aware.

Code generation is about automating the generation of code to implement
repetitive code eventually following design patterns. AOP does not imply
code generation, but since often you need to process and generate code
to implement certain aspects, one thing helps the other.


Jul 17 '05 #37
Hi...

Manuel Lemos wrote:
More features usually means more code.


Funnily enough I don't find that to be true anymore. My experience has
been that the core code gets more highly factored and it shrinks as more
features are added. The incoming code about balances the core shrinkage.

The result of this is that about a third of the way through a project
you tend to hit a maximum code size. My experience of this effect has
been on three largish OO projects all with a refactoring culture.

yours, Marcus
--
Marcus Baker, ma****@lastcraf t.com - http://www.lastcraft.com/
PHP London every first Thursday - http://www.phplondon.org/

Jul 17 '05 #38
Hi...

Tony Marston wrote:
The paradigm (OO or Procedural) is irrelevant. It is all down to how you
implement it.


Well, I used to implement in assembly language, but there is no way I
would want to go back to that if I had a choice. Procedural is the
weakest intersection of OO and functional programming. You are robbed of
polymorphism, which is the most powerful code reduction tool of all.

There are big advantages to using OO on anything over about 100 lines of
code. The main one is that you can express business problems in objects
without the mental translation needed for functional or relational
tools. By working in the language of the domain you make it more likely
that the flex points of your design will match the ones in real life.

When your requirements turn out to be wrong (they always are) the
changes you have to make will either follow the fissures you already
have or will force a change in some of your design. These changes
usually feedback straight into the business model without translation.
These insights usually result in major refactorings that really sort out
the code.

The expressiveness and the insight factor are what makes the OO dominant
paradigm in enterprise programming. It's currently the right tool for
the job.

yours, Marcus
--
Marcus Baker, ma****@lastcraf t.com - http://www.lastcraft.com/
PHP London every first Thursday - http://www.phplondon.org/

Jul 17 '05 #39

"Marcus Baker" <ma****@lastcra ft.com> wrote in message
news:41******** ****@lastcraft. com...
Hi...

Tony Marston wrote:
The paradigm (OO or Procedural) is irrelevant. It is all down to how you
implement it.

Well, I used to implement in assembly language, but there is no way I
would want to go back to that if I had a choice.


You are missing my point. It is possible to use non-OOP and produce
something that shines just as it is possible to use OOP and produce someting
that stinks. It is not what you use but how you use it that counts.
Procedural is the weakest intersection of OO and functional programming.
That's your opinion. I disagree.
You are robbed of polymorphism, which is the most powerful code reduction
tool of all.
Polymorphism is not a code reduction tool, inheritance is.

Code reduction is about having reusable modules so you don't have to keep
rewriting the same code over and over again. You can achieve this with a
class library or a function library. You do not have to use OOP to obtain
reusable code, and you do not have to use OOP to achieve polymorphism.
There are big advantages to using OO on anything over about 100 lines of
code. The main one is that you can express business problems in objects
without the mental translation needed for functional or relational tools.
By working in the language of the domain you make it more likely that the
flex points of your design will match the ones in real life.

When your requirements turn out to be wrong (they always are)
Changes in requirements are down to the client, not the developer.
the changes you have to make will either follow the fissures you already
have or will force a change in some of your design. These changes usually
feedback straight into the business model without translation. These
insights usually result in major refactorings that really sort out the
code.
It does not matter whether your implementation is OO or non-OO, changes is
user requirements will affect both the design as well as the implememtation.
It is just as possible to have an OO design that is difficult to change just
as it is a non-OO design that is easy to change.
The expressiveness and the insight factor are what makes the OO dominant
paradigm in enterprise programming. It's currently the right tool for the
job.


It is not the right tool for every job. A good procedural programmer can
beat the pants off a bad OO programmer every time.

It is not what you use but how you use it that counts.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #40

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11245
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL) on the server because of that. Our site will have an SSL certificate next week, so I would like to use AIM instead of SIM, however, I don't know how to send data via POST over https and recieve data from the Authorize.net server over an https...
2
5840
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues to execute the code until the browser send his reply to the header instruction. So an exit(); after each redirection won't hurt at all
3
23037
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which field is completed.
0
8494
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. 354 roberto@ausone:Build/php-4.3.2> ldd /opt/php4/bin/php libsablot.so.0 => /usr/local/lib/libsablot.so.0 libstdc++.so.5 => /usr/local/lib/libstdc++.so.5 libm.so.1 => /usr/lib/libm.so.1
1
8607
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the column below. The viewer can select states from the drop down lists above the other two columns as well. If the viewer selects only one, only one column fills. If the viewer selects two states, two columns fill. Etc. I could, if appropriate, have...
4
18302
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the user comes back to a page where he had a submitted POST data the browser keeps telling that the data has expired and asks if repost. How to avoid that? I tried registering all POST and GET vars as SESSION vars but
1
6864
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url http://www.mis.gla.ac.uk/biquery/training/ but each of the courses held have maximum of 8 people that could be
2
31442
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value to :parameter I dont like the idea of making the SQL statement on the fly without binding parameters as I dont want a highly polluted SQL cache.
3
23599
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the results of the picture half the size. The PHP I have installed support 1.62 or higher. And all I would like to do is take and image and make it fit a 3x3. Any suggestions to where I should read or look would be appreciated.
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.