Re: OOP leads to lousy websites?
From: Berislav Lopac (berislav.lopac_at_dimedia.hr)
Date: 02/19/04
- Next message: cdt_sylvestre: "query select dates more than one hour"
- Previous message: rush: "Re: OOP leads to lousy websites?"
- In reply to: Chung Leong: "OOP leads to lousy websites?"
- Next in thread: Chung Leong: "Re: OOP leads to lousy websites?"
- Reply: Chung Leong: "Re: OOP leads to lousy websites?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 19 Feb 2004 09:48:02 +0100
Chung Leong wrote:
> There has been a number of threads in this newsgroup concerning OOP
> and PHP. Usually people just debate on which language is more (or
> less) OOP than others. The merit of OOP in the web-programming
> context is rarely addressed. So let me pose this question: Are
> websites built based on OOP principles inherently less stable than
> those built "procedurally?" By "less stable" I mean stability for the
> same amount of programming effort.
>
> I'm incline to think it's true. Take string-handling. To get the
> length of a string procedurally, you do strlen($s), while in OOP you
> would do $s->Length() where $s is an instance of a string class. Now,
> if $s is null, in the first case the function just returns zero,
> whereas in the second case your page fails catastrophically.
OOP is really (in any language, although some give you no alternatives) just
a way to organize your code, and nothing more.
When you think of it, the actual programming is done with only a very small
subset of actual commands in any (high-level) programming languages: not
much more than numerical operators, assignments, if-switches and for loops.
Everything else, from simple ++ and ternary operators, switch statements and
while and other loops, to functions and eventually to objects and methods,
is just tools that make programmer's job easier by helping him reuse the
code and reduce the number of possible problems.
In the end, it all comes down to how good you are in organizing your code.
In the example above, there is no reason why would $s->Length() make the
page fail catastrophically -- you can write it so that the Length() method
also returns a zero. Also, if the strlen is called from another custom which
fails to return zero when strlen returns one to it, the page can fail
catastrophically just the same.
Imagine that there is *no* functions in PHP. No strlen, no in_array,
nothing. Would we be able to program with it just as we do now? Of course,
except that all those useful functions that are precompiled into it will
have to be re-written from scratch using simple operators and if-statements.
In any language, its strength comes primarily in the scope of the code
library which comes with it, and this is especially true of PHP. And this is
true not only for functions, but also for objects, except that here the
library we get with the language is not nearly that extensive. Some
languages, like Java, provide you with a myriad of prepared classes and
objects and interfaces and methods which you can use in your program out of
the box; if they were not there, you would have to write them yourself.
And when you write your own library -- either procedural (functions) or OO
(objects, methods...) -- it is exclusively up to the programmer to cover all
possible incomes and returns to prevent the library from acting
unpredictably. You need to know what objects there might exist in your
application and what functions they might perform, just as you need to know
which chunk of procedural code could become a good function, or whether
there are several functions hiding one inside another.
Some people find it easier to think procedurally, and others find it more
productive to use object-oriented approach; it all comes down to the code
organization.
Berislav
-- If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are Groucho, Chico, and Harpo, then Usenet is Zeppo.
- Next message: cdt_sylvestre: "query select dates more than one hour"
- Previous message: rush: "Re: OOP leads to lousy websites?"
- In reply to: Chung Leong: "OOP leads to lousy websites?"
- Next in thread: Chung Leong: "Re: OOP leads to lousy websites?"
- Reply: Chung Leong: "Re: OOP leads to lousy websites?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|