Re: What's so great about dynamic binding?

paj@uk.co.gec-mrc (Paul Johnson)
20 Nov 1991 09:07:20-GMT

          From comp.compilers

Related articles
Current work in compiler/language design. hackeron@Athena.MIT.EDU (Harris L. Gilliam - MIT Project Athena) (1991-11-10)
What's so great about dynamic binding? spitzak@girtab.usc.edu (1991-11-19)
Re: What's so great about dynamic binding? pardo@cs.washington.edu (1991-11-20)
Re: What's so great about dynamic binding? mlanett@void.ncsa.uiuc.edu (1991-11-20)
Re: What's so great about dynamic binding? barmar@think.com (1991-11-20)
Re: What's so great about dynamic binding? paj@uk.co.gec-mrc (1991-11-20)
| List of all articles for this month |

Newsgroups: comp.compilers
From: paj@uk.co.gec-mrc (Paul Johnson)
Keywords: OOPS, design
Organization: Compilers Central
References: 91-11-030 91-11-071
Date: 20 Nov 1991 09:07:20-GMT

In article 91-11-071 spitzak@girtab.usc.edu (William Spitzak) writes:
>I notice that a whole slew of "hot topics" in object-oriented design were
>listed and that about half of them started with the word "dynamic". This
>concept has always bothered me, because dynamic means interpreted, at some
>level, at least with current machine architectures. If this is true then
>the language should be powerful enought to NOT support dynamic binding, yet
>you can implement any dynamic method you want IN it.


I don't quite understand what you mean. Dynamic, but not dynamic.


Dynamic binding is "interpreted" in the same way that any object code is
"interpreted". The actual dynamic bit (function calls) is implemented
using arrays of function pointers. Of course, being a C++ programmer, you
must know that.


>I have been programming professionally in C++ for about a year now,
>implementing a GUI library, and have used exactly ONE virtual function.


I suspect you have actually been writting a sort of extended C then. You
have not been doing object-oriented programming. A "pointer to a
function" is exactly what a virtual function is.


>I also did a rather quick test - by use of a "pointer to a function"
>in that base class, I was able to eliminate even that virtual
>function. The big loss here is that every sub class needed a
>constructor to fill in that field with the correct pointer (the sort
>of thing we need better languages to automate)...


But C++ virtuals DO automate this! That is what they are for.


I take it back: I always thought that any C++ programmer knew how
virtuals worked. (Some people even hack the _vtable manually.)


>... but I quite successfully fully duplicated the function of the dynamic-
>binding with a static language. The more I work with it, the more I have
>been convinced that an exclusively static-bound language is the way to go.


Take a look at the Xt widget library in X. This is a large library
written in C with arrays of function pointers to do inheritance and
dynamic binding (like you did, but on a much larger scale). The result is
large, flexible, highly reusable and incredibly hairy. C++ virtual
functions hide the hair whilst keeping the other Good Things.


>But since I have been posting on this Bulletin Board I have been flamed
>mercilessly as an Ignoramous for not seeing the marvelous benefits of
>dynamic binding. I'm sorry, I'm blind. I do not see them.


You have used dynamic binding by your function pointer, only you did it
manually. The benefit of dynamic binding is the increased flexibility.
If you want to know more, I really recommend you read "Object-Oriented
Software Construction" by Bertrand Meyer.


Paul.
Paul Johnson (paj@gec-mrc.co.uk). | Tel: +44 245 73331 ext 3245
[I second the suggestion of Meyer's book. It's the best introduction to
OOP that I know. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.