Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #26982

Re: Inheritance

From Bernd Paysan <bernd.paysan@gmx.de>
Newsgroups comp.lang.forth
Subject Re: Inheritance
Date 2013-11-26 22:09 +0100
Organization 1&1 Internet AG
Message-ID <l732ms$h9k$1@online.de> (permalink)
References <52933ba3$0$294$14726298@news.sunsite.dk> <l706q6$c5o$1@online.de> <529473d1$0$297$14726298@news.sunsite.dk>

Show all headers | View raw


Doug Hoffman wrote:

> On 11/25/13 2:01 PM, Bernd Paysan wrote:
> 
>> You forgot one important thing, that is the "combination" stuff.  You
>> might not have deep inheritance trees, but combine different objects into
>> one.
> 
>> Those actors are not instance variables, but instance pointers.
> 
> Are you talking about "instance variables" that are actually embedded
> objects?  If not what are they?  In FMS these are first-class-objects,
> not pointers to objects.  Yes, the instance variables of an object are
> first class objects themselves.

No, I'm very deliberate and did say they are pointed to, and not direct 
instances.  The reason for that is that they can be different classes, and 
different classes have different sizes.  All they have in common is the same 
interface.  They are first-class, too.

You really have to try this, sticking objects together like this to obtain 
various different behavior.  It's a very common design pattern.

>> The typical case I found for calling with self are "template methods",
>> i.e. methods that do something that is filled further down in the
>> inheritance
>> tree.  That also absolutely requires late binding.
> 
> "further down in the inheritance tree".  I was talking about no
> inheritance or shallow inheritance.

Shallow inheritance usually has one level further down.  That's completely 
enough to justify such template methods.

>> I don't understand why you are so obsessed with early binding, and argue
>> with speed.
> 
> Because speed is important.  So is code size.

You missed the point: Speed is not an issue with vtable based late binding, 
nor is code size.  The late binding call is as big as the early binding call 
on x86 (native code assumed, of course).  2 bytes for the fetch the vtable, 
3 bytes for jump short offset+reg, 5 bytes for a call.  Identical code size, 
and in the case of always using the same class identical speed.  The other 
case (real polymorphism) is slower, but then, it does have a functionality 
which early binding simply doesn't have.

>> Contemporary CPUs do quite well on vtable dispatches with their
>> branch target buffers.  They don't do well with a central dispatcher that
>> is more complicated than a simple vtable call, so if you want speed, just
>> make sure that you can implement your system using a vtable.
> 
> If *all* method calls are through vtables then table sizes can get
> large.  This can be a problem.  If large table sizes aren't a concern
> then I agree with your conclusion.

Agreed, you shouldn't have too many methods in a class.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Inheritance Doug Hoffman <glidedog@gmail.com> - 2013-11-25 06:59 -0500
  Re: Inheritance Bernd Paysan <bernd.paysan@gmx.de> - 2013-11-25 20:01 +0100
    Re: Inheritance Doug Hoffman <glidedog@gmail.com> - 2013-11-26 05:11 -0500
      Re: Inheritance Bernd Paysan <bernd.paysan@gmx.de> - 2013-11-26 22:09 +0100
    Re: Inheritance the_gavino_himself <visphatesjava@gmail.com> - 2013-11-27 15:25 -0800
      Re: Inheritance Bernd Paysan <bernd.paysan@gmx.de> - 2013-11-28 01:39 +0100
        Re: Inheritance Mark Wills <markrobertwills@yahoo.co.uk> - 2013-11-28 01:53 -0800
  Re: Inheritance Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-11-25 15:28 -0600
    Re: Inheritance Doug Hoffman <glidedog@gmail.com> - 2013-11-26 05:11 -0500
      Re: Inheritance Bernd Paysan <bernd.paysan@gmx.de> - 2013-11-26 22:28 +0100
        Re: Inheritance Doug Hoffman <glidedog@gmail.com> - 2013-11-26 17:12 -0500
          Re: Inheritance Bernd Paysan <bernd.paysan@gmx.de> - 2013-11-27 23:07 +0100
      Re: Inheritance Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-11-26 17:11 -0600
        Re: Inheritance Doug Hoffman <glidedog@gmail.com> - 2013-11-27 06:25 -0500
          Re: Inheritance Andrew Haley <andrew29@littlepinkcloud.invalid> - 2013-11-27 11:58 -0600

csiph-web