home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / perl / 7573 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  3.0 KB

  1. Path: sparky!uunet!eiffel!eiffel.com
  2. From: ram@eiffel.com (Raphael Manfredi)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Package & Namespace Question
  5. Message-ID: <164@eiffel.eiffel.com>
  6. Date: 21 Dec 92 22:50:43 GMT
  7. References: <1992Dec17.210221.21875@netlabs.com> <163@eiffel.eiffel.com> <1992Dec21.195146.10065@netlabs.com>
  8. Sender: ram@eiffel.com
  9. Organization: Interactive Software Engineering, Santa Barbara CA
  10. Lines: 67
  11.  
  12. Quoting lwall@netlabs.com (Larry Wall) from comp.lang.perl:
  13. >Why can't a program just declare an ANY package if it wants it?  It
  14. >seems to me that the purpose of package main is to be a hodgepodge,
  15. >while the purpose of an ANY package is to be a peg on which to hang a
  16. >(hopefully very minimal) number of global methods.  Some problems are
  17. >better solved with hodgepodges, and some with tightly controlled object
  18. >semantics.  I don't want to confuse the two.  It's not as if an
  19. >object's method can't get at a main subroutine if it wants to
  20. >anyway.
  21.  
  22. Not exactly the same, I think. The purpose of the ANY inheritance is
  23. to provide *any* object with basic routines, so that you may write,
  24. regardless of the object:
  25.  
  26.     new_dog = dog->deep_clone;
  27.  
  28. and get a brand new dog! The deep_clone routine is typically one of
  29. the things you find in the ANY class.
  30.  
  31. But this has only a meaning if the language is purely object oriented,
  32. which perl isn't (not to be construed as a criticism). I don't know
  33. what the syntax for OO calls really is in perl 5, but I guess it would
  34. be acceptable to write:
  35.  
  36.     new_dog = dog->any'deep_clone;
  37.  
  38. The problem is, you need to know whether the DOG class has or has not a
  39. need to redefine deep_clone. Here with my syntax scheme, I am hardwiring
  40. the location of the routine, which is not good in traditional OO schemes,
  41. because this breaks modularity and uniformity of interface.
  42.  
  43. By having DOG explicitely inherit from ANY and then redefine the deep_clone
  44. feature, I guess we would achieve the same function. However, this does not
  45. work if I have a linked list of ANY objects (which I know are DOG objects)
  46. and iterate over the list, calling:
  47.  
  48.     list->item->deep_clone;
  49.  
  50. By making what Eiffel calls a "reverse assignment attempt", I could
  51. "downcast" (C++ terminology) those ANY objects to DOG, by saying
  52.  
  53.     dog ?= list->item;
  54.  
  55. which would either give me a DOG or a Void reference (if the object
  56. was not dynamically an instance of DOG or one of its heirs, i.e. if the
  57. source did not conform to its target assignment variable). Then I can
  58. safely call
  59.  
  60.     dog->deep_clone;
  61.  
  62. if I know there is a DOG-specific version of this routine.
  63.  
  64. I guess this is where OO methodology and traditional functional approach
  65. clash.
  66.  
  67. >Perhaps I ought to rename package main as package GLUE...
  68.  
  69. GLUE *sounds* ugly in French... I prefer main, phonetically speaking.
  70. Although 'main' means 'hand' in French, nobody really says it the French
  71. way :-)
  72.  
  73. Merry Christmas.
  74. -- 
  75. Raphael Manfredi <ram@eiffel.com>
  76. Interactive Software Engineering Inc.
  77. 270 Storke Road, Suite #7                      / Tel +1 (805) 685-1006 \
  78. Goleta, California 93117, USA                  \ Fax +1 (805) 685-6869 /
  79.