home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / next / programm / 6103 < prev    next >
Encoding:
Text File  |  1992-09-10  |  3.4 KB  |  68 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!psinntp!spunky!glitter.RedBrick.COM!jfr
  3. From: jfr@glitter.RedBrick.COM ()
  4. Subject: Re: Multiple init: functions defined
  5. Message-ID: <1992Sep10.034058.13158@RedBrick.COM>
  6. Sender: usenet@RedBrick.COM
  7. Nntp-Posting-Host: glitter.redbrick.com
  8. Organization: Red Brick Systems, Los Gatos, CA
  9. References: <3575@richsun.cpg.trs.reuter.com> <1992Sep6.155059.13349@afs.com> <60157@mimsy.umd.edu>
  10. Date: Thu, 10 Sep 1992 03:40:58 GMT
  11. Lines: 55
  12.  
  13. In article <60157@mimsy.umd.edu> alex@cs.umd.edu (Alex Blakemore) writes:
  14. >In article <1992Sep6.155059.13349@afs.com> greg@afs.com writes:> In artic
  15. >> A selector name, like a C function, should only have one set of  
  16. >> argument types. [Think about it: you wouldn't write two C functions with  
  17. >> the same name, but different arguments, even if they were static to the  
  18. >> module in which they appeared. Well, you might, but you couldn't get a job  
  19. >> with my firm. 8^)]
  20. >
  21. >actually having several functions share a single name can be very useful.
  22. >Its called overloading of course and exists in languages like Ada and C++.
  23. >
  24. >As long as the compiler can resolve the reference to the correct call,
  25. >and you only overload semantically similar operations, it can be a great convenience.
  26.  
  27.   I agree that this can be convenient, but it is also a potential 
  28.   source of problems.  In C++, overloading is almost mandatory to
  29.   support initializers, but in other cases, it is generally only
  30.   a cosmetic.
  31.  
  32. >There's no need to remember half a dozen names for the same conceptual operation.
  33. >you could then use just setValue: instead of setStringValue:, setIntValue:,
  34. >setFloatValue: etc - the compiler can figure out which one you meant from the
  35. >argument type and you can worry about other things.  Its convenient for some
  36. >of the same reasons that polymorphism is.
  37.  
  38.   I used to believe this too.  After thinking about it some more, I realized
  39.   that the problem is NOT really with the issue of overloading, but with the
  40.   fact that the base C datatypes are not first-class objects in Obj-C.  
  41.   Thus I can easily create a single method called setObjectValue:(id)x
  42.   which will take an anonymous object and do internally correct things
  43.   to set the value based on x's class.  This is not possible with regular
  44.   C datatypes, however, since they carry no object identification.  In
  45.   Smalltalk, since all datatypes are classes and everything is an object,
  46.   overloading is implicit since any object can be passed as any parameter
  47.   to any method, as long as the method can deal with that type of object.
  48.   C++ is a compile-time language where overloading makes some sense (and
  49.   is sort of required).  Smalltalk is a run-time language where objects
  50.   can (and should) be dynamically typed, not dealt with by a compiler.
  51.   Obj-C sits on the fence, and while I much prefer it to C++, I still
  52.   feel it has some shortcomings.  
  53.  
  54. >The AppKit would be a lot simpler to learn if Obj C allowed overloading IMHO.
  55. >
  56. >of course it can be abused and lead to confusion - like most powerful features.
  57. >
  58. >I once saw someone spend hours trying to figure out why he got a division by zero
  59. >error on a line that did not contain any division operators.  It turned out he
  60. >had redefined the operators to get a particular form of unit conversion (fine)
  61. >and had cut and pasted the division routine into the multiplication routine.
  62.  
  63.   This is one of the problems with overloading.  
  64.   It is, of course, also a problem with sloppy programming :-)
  65.  
  66.   Jon Rosen
  67.  
  68.