Re: OOP leads to lousy websites?

From: Berislav Lopac (berislav.lopac_at_dimedia.hr)
Date: 02/19/04


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.


Relevant Pages

  • Re: DirectX in HLA
    ... I guess that you have a great knowledge of DirectX ... > understanding by looking at them in assembly language... ... > actually represents, really, is a means to "undo" the OOP so ... > is NOT an "OOPL" (object-orientated programming language), ...
    (comp.lang.asm.x86)
  • Re: DirectX in HLA
    ... I guess that you have a great knowledge of DirectX ... > understanding by looking at them in assembly language... ... > actually represents, really, is a means to "undo" the OOP so ... > is NOT an "OOPL" (object-orientated programming language), ...
    (alt.lang.asm)
  • Re: A Lot of Questions from a Noob
    ... OOP is a language paradigm that is not specific to ... I Google'd for an introduction to object-oriented programming, ... Watch out for the die-hard Perl fanbois: ... PHP 5 OOP has come a long way from PHP 4. ...
    (comp.lang.php)
  • Re: Can a low-level programmer learn OOP?
    ... I have also found some articles profoundly critical of OOP. ... If it does, you'll find it easier, else choose another programming style. ... Starting in 1999 I got back into programming, but the high-level-ness of PC programming and the completely foreign language of OOP repelled me. ... Dynamic languages like Smalltalk, Python or Ruby are much more lightweight in this area, and tend to favor a much more exploratory style - sketch a quick draft on a napkin, start coding, and evolve the design while you're coding. ...
    (comp.lang.python)
  • Re: OO and Extending (Was: Is Procedural Paradigm a basis of OO Paradigm?)
    ... That greatly depends on the language. ... You have to *show* OOP being better, not merely claim you are smart ... I find at least two problems with OO's approach to "extension without ... It works for systems programming, ...
    (comp.object)

Loading