RE: [PHP] What's the use in OOP?

2004-03-31 Thread Peter Albertsson
The OO paradigm maps very closely to problem domains, and is very easy to
model. OO let us build more complex software with less effort.

In general, OO code has more branches and hence use the stack more than
procedural code does. That is why OO code is thought not to be as fast as
procedural code. On the other hand it is easier to build better solutions
when using OOP, and therefore it is often said that applications written in
an OO language is +-10% faster or slower. 

One can use the OO features in PHP without having to worry about performance
penalties. If you are concerned about performance, discussing whether or not
to use OOP in PHP would simply be stupid (don't mean to offend anyone),
there is so many other variables that will have a far bigger impact on
performance than that.

Regards,

Peter Albertsson
Software Engineer and System Architect

-Original Message-
From: Chris Shiflett [mailto:[EMAIL PROTECTED] 
Sent: den 29 mars 2004 23:53
To: Stephen Craton; 'PHP List'
Subject: Re: [PHP] What's the use in OOP?

--- Stephen Craton [EMAIL PROTECTED] wrote:
 I've been reading up on object oriented programming in PHP for a while
 now and I just don't get what's the use in using it. It supposedly
 makes it faster, but I don't really see how in any of my scripts.

Makes it faster in what way? I'm curious to know what you've been reading.

Using objects is generally faster for the programmer and slower for the
computer. YMMV.

 What's the advantage of OOP anyway, and why are so many people using
 it now?

To really understand this, you need to use it. No one can tell you in one
or two lines enough information to explain the entire paradigm or even
convince you of its merits.

The one-liner attempt of mine would be something like:

It helps you associate data with functions that use that data.

There are lots of other things, of course. One method of learning about
this would be to take every OO term (encapsulation, namespacing, etc.) and
find a really good explanation of the term.

Hope that helps.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
 Coming Fall 2004
HTTP Developer's Handbook - Sams
 http://httphandbook.org/
PHP Community Site
 http://phpcommunity.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's the use in OOP?

2004-03-29 Thread Robert Cummings
On Mon, 2004-03-29 at 16:43, Stephen Craton wrote:
 I've been reading up on object oriented programming in PHP for a while now
 and I just don't get what's the use in using it. It supposedly makes it
 faster, but I don't really see how in any of my scripts. What's the
 advantage of OOP anyway, and why are so many people using it now? What does
 it have to offer then just creating files full of functions to include later
 like I've always done?

Inheritance.
Encapsulation.
Polymorphism.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's the use in OOP?

2004-03-29 Thread Jason Giangrande
Stephen Craton wrote:
I've been reading up on object oriented programming in PHP for a while now
and I just don't get what's the use in using it. It supposedly makes it
faster, but I don't really see how in any of my scripts. What's the
advantage of OOP anyway, and why are so many people using it now? What does
it have to offer then just creating files full of functions to include later
like I've always done?
It's really good for code organization and reuse.  The ability to reuse 
code every easily is it's best feature, IMO.

Also, Rob has good points, too.

--
Jason Giangrande [EMAIL PROTECTED]
http://www.giangrande.org
http://www.dogsiview.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] What's the use in OOP?

2004-03-29 Thread Chris Shiflett
--- Stephen Craton [EMAIL PROTECTED] wrote:
 I've been reading up on object oriented programming in PHP for a while
 now and I just don't get what's the use in using it. It supposedly
 makes it faster, but I don't really see how in any of my scripts.

Makes it faster in what way? I'm curious to know what you've been reading.

Using objects is generally faster for the programmer and slower for the
computer. YMMV.

 What's the advantage of OOP anyway, and why are so many people using
 it now?

To really understand this, you need to use it. No one can tell you in one
or two lines enough information to explain the entire paradigm or even
convince you of its merits.

The one-liner attempt of mine would be something like:

It helps you associate data with functions that use that data.

There are lots of other things, of course. One method of learning about
this would be to take every OO term (encapsulation, namespacing, etc.) and
find a really good explanation of the term.

Hope that helps.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
 Coming Fall 2004
HTTP Developer's Handbook - Sams
 http://httphandbook.org/
PHP Community Site
 http://phpcommunity.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's the use in OOP?

2004-03-29 Thread Richard Davey
Hello Stephen,

Monday, March 29, 2004, 10:43:22 PM, you wrote:

SC I've been reading up on object oriented programming in PHP for a while now
SC and I just don't get what's the use in using it. It supposedly makes it
SC faster, but I don't really see how in any of my scripts. What's the
SC advantage of OOP anyway, and why are so many people using it now? What does
SC it have to offer then just creating files full of functions to include later
SC like I've always done?

I used to think the same thing until I started using an OO approach to
development (quite some years ago) and I have to admit I won't ever
revert back to the a hundred different functions spread over stacks
of include files just to get things done approach.

OO doesn't make your code faster, it makes it *neater* and more
intelligible. It also makes development time heck of a lot faster.

Perhaps one approach to this would be to post an example of one of
your scripts (not necessarily the source, more an overview) and then
let someone explain how one OO approach might be to it.

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's the use in OOP?

2004-03-29 Thread William Lovaton
I agree, but the reuse of code is also posible in an structured oriented
fashion and it is not inherent in OOP.

Simply saying that you are going to use OOP doesn't means that the code
reuse is granted, like in structured oriented programming you have to
think very carefully how to design your application to get advantage of
this.


-William


El lun, 29-03-2004 a las 16:52, Jason Giangrande escribió:
 Stephen Craton wrote:
  I've been reading up on object oriented programming in PHP for a while now
  and I just don't get what's the use in using it. It supposedly makes it
  faster, but I don't really see how in any of my scripts. What's the
  advantage of OOP anyway, and why are so many people using it now? What does
  it have to offer then just creating files full of functions to include later
  like I've always done?
 
 It's really good for code organization and reuse.  The ability to reuse 
 code every easily is it's best feature, IMO.
 
 Also, Rob has good points, too.
 
 -- 
 Jason Giangrande [EMAIL PROTECTED]
 http://www.giangrande.org
 http://www.dogsiview.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's the use in OOP?

2004-03-29 Thread Stephen Craton
Thanks for all the replies. I've mostly been reading over at PHP-Builder. I
read one of the articles by Luis Argerich, but since I was only skimming
through the article, I may have missed something and read it wrong.

I used OO in my chat script (can be found at http://php.melchior.us) but it
really seemed like a waste since it was such a small basic script. I never
really find myself re-needing code except for database connectivity and
calling the database and stuff like that.

Thanks again for all the replies and helpful information.

Thanks,
Stephen Craton
http://www.melchior.us
 

- -Original Message-
- From: Chris Shiflett [mailto:[EMAIL PROTECTED]
- Sent: Monday, March 29, 2004 4:53 PM
- To: Stephen Craton; 'PHP List'
- Subject: Re: [PHP] What's the use in OOP?
- 
- --- Stephen Craton [EMAIL PROTECTED] wrote:
-  I've been reading up on object oriented programming in PHP for a while
-  now and I just don't get what's the use in using it. It supposedly
-  makes it faster, but I don't really see how in any of my scripts.
- 
- Makes it faster in what way? I'm curious to know what you've been reading.
- 
- Using objects is generally faster for the programmer and slower for the
- computer. YMMV.
- 
-  What's the advantage of OOP anyway, and why are so many people using
-  it now?
- 
- To really understand this, you need to use it. No one can tell you in one
- or two lines enough information to explain the entire paradigm or even
- convince you of its merits.
- 
- The one-liner attempt of mine would be something like:
- 
- It helps you associate data with functions that use that data.
- 
- There are lots of other things, of course. One method of learning about
- this would be to take every OO term (encapsulation, namespacing, etc.) and
- find a really good explanation of the term.
- 
- Hope that helps.
- 
- Chris
- 
- =
- Chris Shiflett - http://shiflett.org/
- 
- PHP Security - O'Reilly
-  Coming Fall 2004
- HTTP Developer's Handbook - Sams
-  http://httphandbook.org/
- PHP Community Site
-  http://phpcommunity.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's the use in OOP?

2004-03-29 Thread Chris de Vidal
Stephen Craton said:
 I've been reading up on object oriented programming in PHP for a while now
 and I just don't get what's the use in using it. It supposedly makes it
 faster, but I don't really see how in any of my scripts. What's the
 advantage of OOP anyway, and why are so many people using it now? What
 does it have to offer then just creating files full of functions to
 include later like I've always done?

Good question.

OOP is mysterious until you get it, then you'll want to write everything
in objects.  Show a man how to use a hammer, and everything looks like a
nail :-)

One use is to organize loose functions.  For example, we have a user/group
administration section.  Each user is represented with a user object. 
With the user object I put functions inside which do things like Give me
your group ID, Give me your permissions, Give me your name.  So
rather than writing a function for each of these and squirreling it away
into an include file, I organize it into a user class (and squirrel it
away into an include file :-)  Same with groups.

So I wanted to produce a list of users in the group.  I ran something like
this (pseudocode):
$group_obj = new Group (1);
foreach ($group_obj-get_group_list() as $member_id)
 $user_obj = new User (45);
 $user_obj-get_name (); // Displays John

The equivalent standard programming is:
function get_member_name($id)
 $SQL = select name from members where id = $id;
 return $name

function get_group_list ($group_id)
 $SQL = select member_id from groups where group_id = $group_id;
 return $array_of_ids

foreach (get_group_list(1) as $member_id)
 get_member_name ($member_id); // Displays John

A bit messier.  OOP lets each class worry about getting its own data. 
With this organization you can think more clearly about writing the
business logic.  You can build each object to do whatever you need it to
(Tell someone your name when asked, tell someone your blood type when
asked, donate blood when asked), and then go back and build business logic
to orchestrate each action into an application User, who are you?  User,
what is your blood type?  User, donate blood.).

So my use was for organization.

In this example, OOP was actually slower (don't know who told you it'd be
faster; I sure haven't found that to be true) and so eventually I'll
revert to ordinary functional code.  For each time I fetch the member
name, the user's object must be built up and torn down.

Am I doing something wrong?  Perhaps.  But it tells me OOP isn't right for
any and every situation.  Not everything is a nail.

Other uses include extension.  For instance, I might see a class I like
and will download it.  Say I want to impliment it but with a few
customizations; I can extend that class.  In the ordinary function world,
if a new version of a library comes out I'd have to reimpliment those
changes into the library again, but with a class I don't much care which
changes are where (to some extent).

For example, we modified an ordinary menu-building system to be
object-oriented so we could publish it back to the developers.  We then
extended it to do a permission check using the user object above like
this:
get menu items
extension:
 for each menu item, is the user allowed to see it?  If not, remove it
from the list
show menu items

I can now publish that code without the custom permission check and it'll
work for anyone.

It also helps developers segment their work.  For a grand example, take a
look at the Java classes, which are organized in a tree-like fashion.  The
code at the top is generic and it gets more specific as you descend the
tree.  Inheritence is king for Java, and there's very little code rewrite
(if the developer knows what he's doing).

There are a number of other reasons to use OOP, but speed should not be
the first consideration.  Perhaps there are situations in which it is
faster than standard functions but I haven't see them, or perhaps you've
really got to tweak it.  Instead, use OOP for a more organized way to
build a program.

That's my layman's understanding of OOP for laymen like myself.  Hope it
helps!

CD

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's the use in OOP?

2004-03-29 Thread Kelly Hallman
Mar 29 at 5:25pm, Stephen Craton wrote:
 I used OO in my chat script (can be found at http://php.melchior.us) but
 it really seemed like a waste since it was such a small basic script. I
 never really find myself re-needing code except for database
 connectivity and calling the database and stuff like that.

If you take away your class statements, I'd wager that this looks a lot
like it would had you just done it without OOP. It's a design and
organization issue. What you have probably works, but there is so much
more you could do if you spent your time designing objects in the proper
way. Your database connection object is a more logical start...

I think a chat app could easily be something more than just 'functional' 
if you start thinking about the tangible concepts you'd have in some kind 
of chat application-- users, chat sessions, messages. Then later say you 
want to add support for other types of events.. then you think, hey, an 
event is just a different type of message, just extend the message object.

When you've got a bunch of disorganized functions that work in specialized
ways, you are adding on or reworking huge sections of code every time you
want to add or change something. With well designed objects, the worst
case scenario is you write a new object.

I think there is a bit of what I consider an efficiency myth in regards to
OOP in PHP. Most agree that the OO implementation in PHP is not robust.  
However, most people that rely on this assertion do not usually understand
leveraging OO and also most do not write excellent non-OO code. :)

If nothing else, getting a solid handle on the benefits of OOP can only
make your code better, even if you choose not to use it in every situation
(which most would suggest against in PHP, anyway).

There IS something to OOP! Unfortunately, it's difficult to learn through 
examples of car stereo panels or different types of fruit or trees
(though they do make perfect sense in hindsight).

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's the use in OOP?

2004-03-29 Thread Chris Shiflett
--- Kelly Hallman [EMAIL PROTECTED] wrote:
 I think there is a bit of what I consider an efficiency myth in
 regards to OOP in PHP. Most agree that the OO implementation in PHP
 is not robust.

It's much better in PHP 5, although a lack of robustness is not how I
would personally describe PHP 4's shortcomings.

 However, most people that rely on this assertion do not usually
 understand leveraging OO and also most do not write excellent non-OO
 code. :)

Perhaps, but I would say that most people who make this assertion
understand OO. The performance penalty is not a myth. Just as templating
incurs a performance penalty, so does OO. The reward can be worth it, of
course, in terms of organization and ease of use.

The same argument extends further, since I would rather write some things
in PHP or Perl than than C. I know C is faster, but I'm usually more
interested in making things easier on myself.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
 Coming Fall 2004
HTTP Developer's Handbook - Sams
 http://httphandbook.org/
PHP Community Site
 http://phpcommunity.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's the use in OOP?

2004-03-29 Thread Kelly Hallman
Mar 29 at 3:23pm, Chris Shiflett wrote:
  I think there is a bit of what I consider an efficiency myth in
  regards to OOP in PHP. Most agree that the OO implementation in PHP
  is not robust.
 
 It's much better in PHP 5, although a lack of robustness is not how I
 would personally describe PHP 4's shortcomings.

Considering that OO is mostly a convenience for the coder, I just meant
robustness of the implementation in a general sense, nothing specific...

  However, most people that rely on this assertion do not usually
  understand leveraging OO and also most do not write excellent non-OO
 
 Perhaps, but I would say that most people who make this assertion
 understand OO. The performance penalty is not a myth. Just as templating
 incurs a performance penalty, so does OO. The reward can be worth it, of
 course, in terms of organization and ease of use.

I meant most people that rely on this assertion, to avoid learning OO.  
If you have other reasons for not using OO, then great.. but when the
subject is what's the use of OOP? then I think we're talking about two
different groups of people...

 The same argument extends further, since I would rather write some things
 in PHP or Perl than than C. I know C is faster, but I'm usually more
 interested in making things easier on myself.

Precisely! The efficiency myth was meant only in the sense that it's a
myth to think simply avoiding (delving into) OOP because I've heard that
it's slow in PHP automatically means you're being more efficient. It's
not the prime language for OOP but I find that when it all balances out,
for web apps in PHP, OO offers an attractive price/performance ratio...

(can't wait for PHP5)

-- 
Kelly Hallman
// Ultrafancy

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's the use in OOP?

2004-03-29 Thread Robert Cummings
On Mon, 2004-03-29 at 18:23, Chris Shiflett wrote:
 --- Kelly Hallman [EMAIL PROTECTED] wrote:
  I think there is a bit of what I consider an efficiency myth in
  regards to OOP in PHP. Most agree that the OO implementation in PHP
  is not robust.
 
 It's much better in PHP 5, although a lack of robustness is not how I
 would personally describe PHP 4's shortcomings.
 
  However, most people that rely on this assertion do not usually
  understand leveraging OO and also most do not write excellent non-OO
  code. :)
 
 Perhaps, but I would say that most people who make this assertion
 understand OO. The performance penalty is not a myth. Just as templating
 incurs a performance penalty, so does OO. The reward can be worth it, of
 course, in terms of organization and ease of use.

I'd just like to point out as I often do, that the templating system's
implementation determines if there is a performance penalty :)
compiled-to-source templating systems don't incur such a run-time
performance hit, and can in fact increase performance due to the fact
the inclusion happens once at the compile stage. This would be akin to
inlined code :)

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] RE:[PHP]What'stheuseinOOP?

2004-03-29 Thread Chris de Vidal
Stephen Craton said:
 I used OO in my chat script (can be found at
 http://php.melchior.us) but it really seemed like a waste
 since it was such a small basic script. I never
 really find myself re-needing code except for database
 connectivity and calling the database and stuff like that.

My boss, before he really understood OOP, would take ordinary proceedural
code and wrap it in a class, which still wasn't object-oriented.  I fear
you've done the same in your code (even though I haven't seen it) and are
wondering what the big whoop is about.  I believe that if you don't
understand OO, you haven't been using OO.

Once you understand the whys (after using it for a bit) you'll see why
it's so cool.  Now I wanna code everything OO :-)

I really understood it when a Java programmer I know once said In
proceedural code, the nuts-and-bolts are functions which are verbs
(get_data(), open_database(), write_file()) while in object-oriented code,
the nuts and bolts are objects which are nouns ($user, $group, $job,
$house).

So I'd build an OO chat room like so (pseudocode):
class chatroom
 values: private or public, admin, name, max_users, comments, admin_present
 methods: get/set_public_or_private, get/set_admin, get/set_name,
get/set_max_users, get/set_comments, display_help, update_member_list,
get/set_admin_present
class user
 values: permission level, name, email address, password
 methods: get/set permission level, get/set name, get/set email_address,
get/set password, join_chat_room, create_chat_room, leave_chat_room
class system chatroom extends chatroom
 methods: check permissions, restart server

$phpchat = new chatroom (phpchat);
$phpchat-set_public_or_private (public);
$phpchat-set_admin ([EMAIL PROTECTED]);
$phpchat-set_comments (A great place to talk about PHP);

$user- new user ([EMAIL PROTECTED]);
$user-join_chat_root (phpchat);
if ($phpchat-get_admin() == $user-get_email_address()) {
$phpchat-set_admin_present(TRUE); }
$phpchat-update_member_list();
...

It's not perfect but hopefully you'll understand the magic.
/dev/idal

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's the use in OOP?

2004-03-29 Thread Chris Shiflett
--- Robert Cummings [EMAIL PROTECTED] wrote:
  Perhaps, but I would say that most people who make this assertion
  understand OO. The performance penalty is not a myth. Just as
  templating incurs a performance penalty, so does OO. The reward
  can be worth it, of course, in terms of organization and ease of
  use.
 
 I'd just like to point out as I often do, that the templating
 system's implementation determines if there is a performance
 penalty :) compiled-to-source templating systems don't incur such
 a run-time performance hit

Then OOP isn't slower either, because you can use something like APC.

Moral of the story: that argument is irrelevant. :-)

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security - O'Reilly
 Coming Fall 2004
HTTP Developer's Handbook - Sams
 http://httphandbook.org/
PHP Community Site
 http://phpcommunity.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php