Path: utzoo!attcan!uunet!midway!ncar!zaphod.mps.ohio-state.edu!usc!snorkelwacker!mintaka!spdcc!esegue!compilers-sender From: px@fctunl.rccn.pt (Joaquim Baptista [pxQuim]) Newsgroups: comp.compilers Subject: Re: Defining polymorphism vs. overloading Keywords: polymorphism Message-ID: Date: 20 Sep 90 18:53:19 GMT References: <19400003@inmet> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: px@fctunl.rccn.pt (Joaquim Baptista [pxQuim]) Organization: Universidade Nova de Lisboa -- Lisbon, Portugal Lines: 42 Approved: compilers@esegue.segue.boston.ma.us In-Reply-To: stt@inmet.inmet.com's message of 15 Sep 90 14:32:00 GMT In article <19400003@inmet> stt@inmet.inmet.com writes: Here is my favorite so far: > - Overloading is the ability to have the same name (symbol) attached > to different entities (functions, procedures, variables or whatsoever). > > - Polymorphism is the ability to have the compiler decide *at runtime* > which entity to use depending on the runtime type (class or whatever) > of the contents of variables. > > - Generic code is a chunk of code that has the ability of performing > the same algorithm with more than one type. The actual types may be > known at runtime (as in Smalltalk) or at compile time (as in Ada). > . . . > Joaquim Manuel Soares Baptista, aka px@fctunl.rccn.pt, px@unl.uucp However, I would revise the definition of polymorphism as follows: - Polymorphism is the ability to have a single entity (usually a parameter or a pointer) refer to objects/values of more than one type. Run-time polymorphism (like C++) allows the dispatch to type-specific code to be made at run-time. Compile-time polymorphism (like Ada's generics) performs the "dispatch" to type-specific code at compile-time. It's always nice to be appreciated, but still I must disagree with you. I disagree with your difference of run-time vs. compile-time polymorphism. I call the first polymorphism and the second one overloading. Although they look similar, they have a different expressive power. Run-time dispatching is more powerful than compile-time "dispatching", and I think that they deserve different names, ie, polymorphism and overloading. I can elaborate on this "expressive power" business if that proves to be necessary. -- Joaquim Manuel Soares Baptista, aka px@fctunl.rccn.pt, px@unl.uucp Snail: CRIA, UNINOVA, FCT/UNL, 2825 Mt Caparica, Portugal -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.