[Sussex] Simple OOP tutorial

Geoff Teale gteale at cmedltd.com
Fri Aug 27 09:28:59 UTC 2004


I suppose it's time I waded in.  I shall address you all now in my role
of the right reverend G.J. Teale, priest of the Church of Emacs, Vicar
of the ward of St. IGNUcius, Knight of the Lambda Calculus and
programmer of some note ( A note other than C# I should point out -
although someone should explain enharmonic equivalence to Microsoft, C#
is also D flat ).  


Here beginith the lesson...

On the 26th day of the month named for Augustus the reclusive monk
Gareth of Ablett spake thus:

>I wouldn't call it an Oxymoron as I still has OO methods within its
>language and even more so with PHP5 which is now on a full release.

Hear me now good children.  Many a waey sinner has been tempted to dip
into OO like some kind of library.  A half-hearted attempt at OO
programming is the root of much evil.  

If you can afford it I would go for this:

http://www.amazon.co.uk/exec/obidos/ASIN/0805353402/qid=1093595691/ref=sr_8_xs_ap_i1_xgl/026-7682564-2094815

.. followed up by the Gang of Four's "Design Patterns" (Gamma, Helm,
Johnson & Vlissides) for some practical examples of good usage.


>If its for PHP you want to know OOP then C is somewhat different and
>probably not a good idea to look at unless you are going to be using C.


Do not be fooled C is not an OO language though it be a thing of beauty
all the same. ;)  C's younger brothers Objective-C and C++ quarralled
and C++ being the fatter of the two squashed Objective-C though he was
good in the eyes of the programmers.  Objective-C can now only be in
the garden of computing eden where he resides with the Apple, though he
also props up the GNU Step of which many have heard, but few have used.

C++ has in turn grown strong, and less evil.  C++ has become more than
an OO language.  C++ made a bargin with the maiden SGI, adopting her son
STL and STL's father Generic Programming. C++ a very big and fat and
will confuse all but the greatest monks wishing to find enlightenment.

>With the newer php5 nearly all tutorials you will find at the moment
>that are for PHP5 will be using classes so just do a plain google
>search. Failing that I got some good links I can hook out later tonight

Ah do not be tempted, it is a flase path.  What I've read on web sites
about PHP's attempts at OO reminds me of pre-.NET Visual Basic.  When I
was a novice I was tempted by this language in return for financial
rewards.  Visual Basic (and it seems PHP) are about as Object Orientated
as Messers K. Marx and V. I. Lenin.

A reading from chapter 6 of "the big boys book of programming":

There are numerous sins and fals paths in the road to OOP.  The wise
programmer should remember the rules carved on the grave of Simula:

- If you just want to learn how to use PHP's "classes" go buy a PHP5 book
  and don't try to think of it as pure OO.

- If you want to learn about OO (A nobler aim and more widely applicable
  skill) go and invest some time in learning SmallTalk.

- Whatever you do don't try and learn anything about OOP by learning
  Java - it will teach you some very broken concepts which you will
  spout continuously to the embaressment of yourself and everyone
  around you (sorry, a little too much practical experience of Java
  programmers...).

- Don't try to learn OOP with perl - It's like learning to write with a
  flint and a cave wall.

- Don't try to learn OOP with python - it's a great language but it has
  no serious concept of encapsulation - which is OK (but not great) in
  practical use, but it's not teaching you the full picture.  Moreover
  its inheretance model is a little messy in places.

- If you value you your sanity avoid anything with LISP in it's name.

More important than all of that is this:

OO is a great and powerful tool but it is not the only one, nor is
always the best way of doing things.  Most of the code I am working on
outside of work now is in C, straight up, procedural C.  Why?  Well,
the programs I am writing are low(ish) level system code and one
important part of their design is that they must run quickly.  Having
no human interaction means that their process is very much linear and
their design has a lot more to do with the way a computer actually
works than the vague notions that appeal to human users.  They are
written in C because it is less time consuming and more portable than
assembly.  Object Orientism promotes an idea of interacting objects
that are instances of classes.  It is important to remeber that these
ideas or interaction and co-operation are actually just a facade in
terms of how the program will actually run (as a series of sequential
commands) - there are a number of classes of system development in
which this kind of simplified view of a programs execution is actually
counter-intuitive and counter productive.

It is noteable however that the human configuration aspects of these
tools will almost definetly be written in Object Orientated code and
probably in a light weight scripting langauge (Ruby or Python).

Object Orientism is a useful way to simplify the modelling of real world
processes and interactions and a powerful tool for code re-use, but many
problems (especially those that don't reflect human processes) do not
fit simply or effeciently into that model.  It is the duty of any _good_
programmer to understand thoroughly the toolkit that is available to
him/her and apply those tools appropriately.  

Here endeth the lesson.

-- 
Geoff Teale




More information about the Sussex mailing list