Re: OO in Forth



Thomas Pornin wrote:
According to Doug Hoffman <dhoffman@xxxxxxxxxxxxxxx>:
No. Whether or not there are subclasses with overriding methods has
no bearing at all on the compiler's ability to decide to early or late
bind.

I beg to disagree. If the compiler can prove, through static analysis,
that the value on which it is calling a method named "foo" relates to
class C or a subclass thereof, and if the compiler simultaneously has
knowledge of all subclasses of C that may exist at runtime, and none
of them overrides "foo", then the compiler can safely convert the method
call to a direct function call, i.e. perform early binding.

I think we must be talking apples and oranges. You clipped important parts of my statement. I said:

"No. Whether or not there are subclasses with overriding methods has no bearing at all on the compiler's ability to decide to early or late bind. All the compiler need know is the *class* of *that particular object* at compile time. The class of that object could have 100 subclasses with or without method overriding, or no subclasses at all. It makes no difference."

Perhaps it's because Neon uses Smalltalk-like binding.


Here's an example to illustrate my point:

:class foo1
:m draw: ." foo1" ;m
;class

:class foo2
:m draw: ." foo2" ;m
;class

Now, let's instantiate two objects and send each the draw: message:

foo1 obj1
foo2 obj2

draw: obj1 foo1 ok \ an early bind
draw: obj2 foo2 ok \ an early bind

The compiler will use early binding in both cases because it knows the classes of each object at compile time.


Now let's create a subclass that overrides the draw: method:

:class foo3 <super foo1
:m draw: ." foo3" ;m
;class

foo3 obj3

draw: obj3 foo3 ok \ an early bind

Now if we go back and instantiate another foo1 object we get the following:

foo1 obj1a

draw: obj1a foo1 ok \ this will again be an early bind

The existence of the subclass foo3 and/or its draw: method overriding had *no bearing* on the compiler's decision to early bind or late bind to the foo1 object.

Analogous results would be achieved had we defined draw: to be a late bind in classes foo1 foo2 and foo3 or mixed it up (the late bind of course is not necessary in this example). The compiler will use the binding (late or early) prescribed by the class. The existence of subclasses and what they do with that selector has no bearing.

QED

Again, I have to think that you, Andrew, and I are not talking about the same thing or are mis-communicating somehow.

-Doug
.



Relevant Pages

  • Re: Book on Pre-MATH for cryptography and cryptanalysis.
    ... I'll fly rightly or Ramzi will draw the ... philosophys. ... To be just or dual will sit quaint squares to subtly ... bind. ...
    (sci.crypt)
  • Re: Databinding Wishlist
    ... bind to say an specific collection element. ... > COMPILER CHECKED BINDING ... > To be able to bind a properties in a way that is checked by the compiler> rather than waiting for a possible runtime error due to a typo. ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • Compiler Warning C4373 about virtual methods
    ... The following code will result in C4373 warning message. ... What means "bind"? ... either the base or derived class. ... Versions of the compiler prior to Visual C++ 2008 bind the function to the ...
    (microsoft.public.vc.language)
  • Re: Parse library
    ... The html doco on bind are available at ... My format might support something like: ... > but you could easily evolve the compiler to spit out another format if you ... With a parser module, you'd ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: NAG ware linking problem
    ... SUBROUTINE antfarm() bind ... I don't have the V51 compiler on my Mac yet, so I can't test this there. ... It does give a warning message for the use of BIND, ...
    (comp.lang.fortran)