home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!eiffel!eiffel.com
- From: ram@eiffel.com (Raphael Manfredi)
- Newsgroups: comp.lang.perl
- Subject: Re: Package & Namespace Question
- Message-ID: <164@eiffel.eiffel.com>
- Date: 21 Dec 92 22:50:43 GMT
- References: <1992Dec17.210221.21875@netlabs.com> <163@eiffel.eiffel.com> <1992Dec21.195146.10065@netlabs.com>
- Sender: ram@eiffel.com
- Organization: Interactive Software Engineering, Santa Barbara CA
- Lines: 67
-
- Quoting lwall@netlabs.com (Larry Wall) from comp.lang.perl:
- >Why can't a program just declare an ANY package if it wants it? It
- >seems to me that the purpose of package main is to be a hodgepodge,
- >while the purpose of an ANY package is to be a peg on which to hang a
- >(hopefully very minimal) number of global methods. Some problems are
- >better solved with hodgepodges, and some with tightly controlled object
- >semantics. I don't want to confuse the two. It's not as if an
- >object's method can't get at a main subroutine if it wants to
- >anyway.
-
- Not exactly the same, I think. The purpose of the ANY inheritance is
- to provide *any* object with basic routines, so that you may write,
- regardless of the object:
-
- new_dog = dog->deep_clone;
-
- and get a brand new dog! The deep_clone routine is typically one of
- the things you find in the ANY class.
-
- But this has only a meaning if the language is purely object oriented,
- which perl isn't (not to be construed as a criticism). I don't know
- what the syntax for OO calls really is in perl 5, but I guess it would
- be acceptable to write:
-
- new_dog = dog->any'deep_clone;
-
- The problem is, you need to know whether the DOG class has or has not a
- need to redefine deep_clone. Here with my syntax scheme, I am hardwiring
- the location of the routine, which is not good in traditional OO schemes,
- because this breaks modularity and uniformity of interface.
-
- By having DOG explicitely inherit from ANY and then redefine the deep_clone
- feature, I guess we would achieve the same function. However, this does not
- work if I have a linked list of ANY objects (which I know are DOG objects)
- and iterate over the list, calling:
-
- list->item->deep_clone;
-
- By making what Eiffel calls a "reverse assignment attempt", I could
- "downcast" (C++ terminology) those ANY objects to DOG, by saying
-
- dog ?= list->item;
-
- which would either give me a DOG or a Void reference (if the object
- was not dynamically an instance of DOG or one of its heirs, i.e. if the
- source did not conform to its target assignment variable). Then I can
- safely call
-
- dog->deep_clone;
-
- if I know there is a DOG-specific version of this routine.
-
- I guess this is where OO methodology and traditional functional approach
- clash.
-
- >Perhaps I ought to rename package main as package GLUE...
-
- GLUE *sounds* ugly in French... I prefer main, phonetically speaking.
- Although 'main' means 'hand' in French, nobody really says it the French
- way :-)
-
- Merry Christmas.
- --
- Raphael Manfredi <ram@eiffel.com>
- Interactive Software Engineering Inc.
- 270 Storke Road, Suite #7 / Tel +1 (805) 685-1006 \
- Goleta, California 93117, USA \ Fax +1 (805) 685-6869 /
-