home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / next / programm / 6054 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  2.0 KB

  1. Path: sparky!uunet!dtix!mimsy!alex
  2. From: alex@cs.umd.edu (Alex Blakemore)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Re: Multiple init: functions defined
  5. Message-ID: <60157@mimsy.umd.edu>
  6. Date: 8 Sep 92 17:14:30 GMT
  7. References: <3575@richsun.cpg.trs.reuter.com> <1992Sep6.155059.13349@afs.com>
  8. Sender: news@mimsy.umd.edu
  9. Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
  10. Lines: 33
  11.  
  12. In article <1992Sep6.155059.13349@afs.com> greg@afs.com writes:> In artic
  13. > A selector name, like a C function, should only have one set of  
  14. > argument types. [Think about it: you wouldn't write two C functions with  
  15. > the same name, but different arguments, even if they were static to the  
  16. > module in which they appeared. Well, you might, but you couldn't get a job  
  17. > with my firm. 8^)]
  18.  
  19. actually having several functions share a single name can be very useful.
  20. Its called overloading of course and exists in languages like Ada and C++.
  21.  
  22. As long as the compiler can resolve the reference to the correct call,
  23. and you only overload semantically similar operations, it can be a great convenience.
  24.  
  25. There's no need to remember half a dozen names for the same conceptual operation.
  26. you could then use just setValue: instead of setStringValue:, setIntValue:,
  27. setFloatValue: etc - the compiler can figure out which one you meant from the
  28. argument type and you can worry about other things.  Its convenient for some
  29. of the same reasons that polymorphism is.
  30.  
  31. The AppKit would be a lot simpler to learn if Obj C allowed overloading IMHO.
  32.  
  33. of course it can be abused and lead to confusion - like most powerful features.
  34.  
  35. I once saw someone spend hours trying to figure out why he got a division by zero
  36. error on a line that did not contain any division operators.  It turned out he
  37. had redefined the operators to get a particular form of unit conversion (fine)
  38. and had cut and pasted the division routine into the multiplication routine.
  39.  
  40.  
  41.  
  42. -- 
  43. ---------------------------------------------------
  44. Alex Blakemore alex@cs.umd.edu   NeXT mail accepted
  45.