Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Machines take me by surprise with great frequency. -- Alan Turing


devel / comp.lang.misc / OO object layout - method-table pointer or tag

SubjectAuthor
* OO object layout - method-table pointer or tagJames Harris
+* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
|`* Re: OO object layout - method-table pointer or tagJames Harris
| +* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |`* Re: OO object layout - method-table pointer or tagJames Harris
| | `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |  `* Re: OO object layout - method-table pointer or tagJames Harris
| |   +* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |`* Re: OO object layout - method-table pointer or tagJames Harris
| |   | `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |  `* Re: OO object layout - method-table pointer or tagJames Harris
| |   |   `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |    `* Re: OO object layout - method-table pointer or tagJames Harris
| |   |     `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |      `* Re: OO object layout - method-table pointer or tagJames Harris
| |   |       `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |   |        `- Re: OO object layout - method-table pointer or tagJames Harris
| |   `* Re: OO object layout - method-table pointer or tagBart
| |    `* Re: OO object layout - method-table pointer or tagJames Harris
| |     `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |      `* Re: OO object layout - method-table pointer or tagJames Harris
| |       `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        +* Re: OO object layout - method-table pointer or tagBart
| |        |`* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        | `* Re: OO object layout - method-table pointer or tagBart
| |        |  `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |   `* Re: OO object layout - method-table pointer or tagBart
| |        |    `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |     `* Re: OO object layout - method-table pointer or tagBart
| |        |      +- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |      `* Re: OO object layout - method-table pointer or tagBart
| |        |       `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |        `* Re: OO object layout - method-table pointer or tagBart
| |        |         `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |          `* Re: OO object layout - method-table pointer or tagBart
| |        |           `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |        |            `- Re: OO object layout - method-table pointer or tagBart
| |        `* Re: OO object layout - method-table pointer or tagJames Harris
| |         `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |          `* Re: OO object layout - method-table pointer or tagJames Harris
| |           `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |            `* Re: OO object layout - method-table pointer or tagJames Harris
| |             `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |              `* Re: OO object layout - method-table pointer or tagJames Harris
| |               `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                `* Re: OO object layout - method-table pointer or tagJames Harris
| |                 `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                  `* Re: OO object layout - method-table pointer or tagJames Harris
| |                   `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                    `* Re: OO object layout - method-table pointer or tagJames Harris
| |                     `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                      `* Re: OO object layout - method-table pointer or tagJames Harris
| |                       `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
| |                        `- Re: OO object layout - method-table pointer or tagJames Harris
| `* Re: OO object layout - method-table pointer or tagluserdroog
|  `- Re: OO object layout - method-table pointer or tagJames Harris
+- Re: OO object layout - method-table pointer or tagDavid Brown
`* Re: OO object layout - method-table pointer or tagBart
 `* Re: OO object layout - method-table pointer or tagJames Harris
  +* Re: OO object layout - method-table pointer or tagDavid Brown
  |+- Re: OO object layout - method-table pointer or tagBart
  |`- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
  `* Re: OO object layout - method-table pointer or tagBart
   `* Re: OO object layout - method-table pointer or tagJames Harris
    `* Re: OO object layout - method-table pointer or tagBart
     +- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
     `* Re: OO object layout - method-table pointer or tagJames Harris
      `* Re: OO object layout - method-table pointer or tagBart
       `* Re: OO object layout - method-table pointer or tagJames Harris
        `* Re: OO object layout - method-table pointer or tagBart
         `* Re: OO object layout - method-table pointer or tagJames Harris
          +- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
          `* Re: OO object layout - method-table pointer or tagBart
           +* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           |`* Re: OO object layout - method-table pointer or tagBart
           | +* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |`* Re: OO object layout - method-table pointer or tagBart
           | | `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |  `* Re: OO object layout - method-table pointer or tagBart
           | |   `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |    `* Re: OO object layout - method-table pointer or tagBart
           | |     `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      +* Re: OO object layout - method-table pointer or tagBart
           | |      |`* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      | `* Re: OO object layout - method-table pointer or tagBart
           | |      |  `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   +* Re: OO object layout - method-table pointer or tagBart
           | |      |   |`* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   | `* Re: OO object layout - method-table pointer or tagBart
           | |      |   |  `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   |   `* Re: OO object layout - method-table pointer or tagBart
           | |      |   |    `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   |     `* Re: OO object layout - method-table pointer or tagBart
           | |      |   |      +- Re: OO object layout - method-table pointer or tagMike Austin
           | |      |   |      `- Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |   `* Re: OO object layout - method-table pointer or tagJames Harris
           | |      |    `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |     `* Re: OO object layout - method-table pointer or tagJames Harris
           | |      |      `* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |       +* Re: OO object layout - method-table pointer or tagJames Harris
           | |      |       |+* Re: OO object layout - method-table pointer or tagDmitry A. Kazakov
           | |      |       |`- Re: OO object layout - method-table pointer or tagDavid Brown
           | |      |       `* Re: OO object layout - method-table pointer or tagBart
           | |      `* Re: OO object layout - method-table pointer or tagJames Harris
           | `* Re: OO object layout - method-table pointer or tagJames Harris
           +* Re: OO object layout - method-table pointer or tagDavid Brown
           `* Re: OO object layout - method-table pointer or tagJames Harris

Pages:123456
OO object layout - method-table pointer or tag

<sggjdi$trv$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=615&group=comp.lang.misc#615

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: OO object layout - method-table pointer or tag
Date: Sun, 29 Aug 2021 19:24:50 +0100
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <sggjdi$trv$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 29 Aug 2021 18:24:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="910fd76f7a555dbf2b117352c39afd0e";
logging-data="30591"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XpdYRl4x9ryf88TSftzYzHoiYR5kpzmM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Fsc09LuwZwyDA00OfngBR+NFLiM=
Content-Language: en-GB
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: James Harris - Sun, 29 Aug 2021 18:24 UTC

I am a long way from implementing OO-type objects but I have in mind a
layout for them and something Dmitry mentioned in another thread
suggested that there may be a better way.

My intended model is to have each object's data preceded by a pointer to
a table of its methods. To illustrate, let's say the source code had a
structure 'point' with two fields (x and y) and which referred to two
methods (plot and clear).

Each 'point' would have the coordinates and the two methods mentioned
such that if we had a point P then

P.x would refer to the x coordinate
P.plot() would invoke the plot method

My idea is to implement that as two parts. Each object would have a
read-write part as

pointer to method table
x
y

and the pointer therein would point to a read-only 'method table' which
had the records and some other fields, such as

number of objects pointing at this table
pointer to the type
pointer to procedure 'plot'
pointer to procedure 'clear'

Sorry if that looks a bit complicated. It's about as short as I can
think to make it. Basically, the method table would contain a count of
the number of objects which were pointing at it, a pointer to the type
definition, and a pointer to each method.

I chose it that way to make it fast to dispatch one of the procedures:
follow one pointer to get to the method table then invoke the routine
pointed to by the pointer at the designated offset. (The routine would
be supplied a pointer to the object.)

To get to base info about the type would also be possible by following
the pointer to the type.

Opinions on the scheme?

However Dmitry said: "You do not need length, because it can be deduced
from the tag. Then tag is more universal than a pointer to the table.
Pointer do not work with multiple-dispatch, for example."

Ignoring the length part (as some objects would have their own length
and some would not but that difference is immaterial here) how would a
'tag' system be laid out in memory and how would one use that to locate
a method?

--
James Harris

Re: OO object layout - method-table pointer or tag

<sggnc4$o9c$2@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=622&group=comp.lang.misc#622

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!Hx95GBhnJb0Xc8StPhH8AA.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Sun, 29 Aug 2021 21:32:21 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sggnc4$o9c$2@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="24876"; posting-host="Hx95GBhnJb0Xc8StPhH8AA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Sun, 29 Aug 2021 19:32 UTC

On 2021-08-29 20:24, James Harris wrote:

> Ignoring the length part (as some objects would have their own length
> and some would not but that difference is immaterial here) how would a
> 'tag' system be laid out in memory and how would one use that to locate
> a method?

You must consider the following inheritance variants:

1. Multiple inheritance (MI)

A B
\ /
C

1.1. Java model. This is when only one parent may have an implementation
(e.g. members). Thus you have a single path where you could keep vptr
[the limited model you have in mind].

1.2. Full MI, C++ model. Any parent may have an implementation. This in
particular means that when you pass C as A you must have vptr of
A'Class, when you pass C as B, you must have another vptr of B'Class.

1.3. Idempotent inheritance:

A
/ \
B C
\ /
D

D has the single instance of A inherited over B and C.

1.4. Additive inheritance:

A
/ \
B C
\ /
D

D has two instances of A, one inherited over B another over C.

2. Multiple dispatch.

2.1. Multimethods only. A multimethod is when all arguments and results
are from the same type hierarchy. E.g. arithmetic operations are
multimethods. Multimethods can have vptr, but the table becomes
multidimensional.

2.2. Parallel inheritance. Arguments can be from different hierarchies,
but only diagonal combinations are allowed:

A1 B1
| |
A2 B2

Foo (A1, B1) - OK
Foo (A1, B2) - not OK
Foo (A2, B2) - OK

This is very common case, e.g. when you have a hierarchy of array
element types parallel to the corresponding array types.

2.3. Full multiple dispatch. Any combinations allowed.

3. Embedded vs. outside tags. If you embed the tag into the object, you
cannot have classes of scalar types.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sggu6b$bhm$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=626&group=comp.lang.misc#626

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Sun, 29 Aug 2021 23:28:42 +0200
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <sggu6b$bhm$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 29 Aug 2021 21:28:43 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4d2087e7145ef416b70be102073fa784";
logging-data="11830"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OAonofTYapWy0VT3ElBE03QSs60XQr2Q="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:albArW84vgYi6vH+itBVwdzjgcs=
In-Reply-To: <sggjdi$trv$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sun, 29 Aug 2021 21:28 UTC

On 29/08/2021 20:24, James Harris wrote:
> I am a long way from implementing OO-type objects but I have in mind a
> layout for them and something Dmitry mentioned in another thread
> suggested that there may be a better way.
>
> My intended model is to have each object's data preceded by a pointer to
> a table of its methods. To illustrate, let's say the source code had a
> structure 'point' with two fields (x and y) and which referred to two
> methods (plot and clear).
>
> Each 'point' would have the coordinates and the two methods mentioned
> such that if we had a point P then
>
>   P.x        would refer to the x coordinate
>   P.plot()   would invoke the plot method
>
> My idea is to implement that as two parts. Each object would have a
> read-write part as
>
>     pointer to method table
>     x
>     y
>
> and the pointer therein would point to a read-only 'method table' which
> had the records and some other fields, such as
>
>     number of objects pointing at this table
>     pointer to the type
>     pointer to procedure 'plot'
>     pointer to procedure 'clear'
>
>
> Sorry if that looks a bit complicated. It's about as short as I can
> think to make it. Basically, the method table would contain a count of
> the number of objects which were pointing at it, a pointer to the type
> definition, and a pointer to each method.
>

So far, that is a straight copy of C++ (without virtual inheritance
support - and it's questionable whether virtual inheritance is useful
enough to justify its complications).

> I chose it that way to make it fast to dispatch one of the procedures:
> follow one pointer to get to the method table then invoke the routine
> pointed to by the pointer at the designated offset. (The routine would
> be supplied a pointer to the object.)
>
> To get to base info about the type would also be possible by following
> the pointer to the type.
>
> Opinions on the scheme?

It works for C++.

Re: OO object layout - method-table pointer or tag

<sgh09l$r5k$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=627&group=comp.lang.misc#627

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Sun, 29 Aug 2021 23:04:35 +0100
Organization: A noiseless patient Spider
Lines: 129
Message-ID: <sgh09l$r5k$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 29 Aug 2021 22:04:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d34df35c3798e2c34a1b8f95ab27c825";
logging-data="27828"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1Je3AKj41UNNCbKIcAq/nngtlSj1sFqs="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:MxoYZPhJuSRutDhR1nuWee89UIU=
In-Reply-To: <sggjdi$trv$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210829-8, 29/8/2021), Outbound message
 by: Bart - Sun, 29 Aug 2021 22:04 UTC

On 29/08/2021 19:24, James Harris wrote:
> I am a long way from implementing OO-type objects but I have in mind a
> layout for them and something Dmitry mentioned in another thread
> suggested that there may be a better way.
>
> My intended model is to have each object's data preceded by a pointer to
> a table of its methods. To illustrate, let's say the source code had a
> structure 'point' with two fields (x and y) and which referred to two
> methods (plot and clear).
>
> Each 'point' would have the coordinates and the two methods mentioned
> such that if we had a point P then
>
>   P.x        would refer to the x coordinate
>   P.plot()   would invoke the plot method
>
> My idea is to implement that as two parts. Each object would have a
> read-write part as
>
>     pointer to method table
>     x
>     y
>
> and the pointer therein would point to a read-only 'method table' which
> had the records and some other fields, such as
>
>     number of objects pointing at this table
>     pointer to the type
>     pointer to procedure 'plot'
>     pointer to procedure 'clear'
>
>
> Sorry if that looks a bit complicated. It's about as short as I can
> think to make it. Basically, the method table would contain a count of
> the number of objects which were pointing at it, a pointer to the type
> definition, and a pointer to each method.
>
> I chose it that way to make it fast to dispatch one of the procedures:
> follow one pointer to get to the method table then invoke the routine
> pointed to by the pointer at the designated offset. (The routine would
> be supplied a pointer to the object.)
>
> To get to base info about the type would also be possible by following
> the pointer to the type.
>
> Opinions on the scheme?
>
> However Dmitry said: "You do not need length, because it can be deduced
> from the tag. Then tag is more universal than a pointer to the table.
> Pointer do not work with multiple-dispatch, for example."
>
> Ignoring the length part (as some objects would have their own length
> and some would not but that difference is immaterial here) how would a
> 'tag' system be laid out in memory and how would one use that to locate
> a method?
>

I haven't implemented this stuff in static code: classes with methods
and with inheritance, so can't speak directly from experience.

I have played with it however, and I have implemented it for dynamic code.

The first thing that strikes me, if I understood correctly, is that each
instance of a Point needs to include not only the data x,y, but also a
pointer.

With apparently, exactly the same pointer in each of millions of
instances. Which all means that if you allocate an array of such points,
you can't just initialise them with all-zeros to (0,0), but need to
specifically initialise that pointer field in each one.

So, why is that actually necessary? Is it because of inheritance, where
any instance P could be of the base class, or of a derived class which
could have its own sets of methods, and this information is not known
until runtime?

I can illustrate that with this example in dynamic code:

record point =
var x,y
proc plot(&self) =
println "POINT",self.x,self.y
end
end

record dirvec(point) = # inherit from Point
proc plot(&self) =
println "DIRVEC",self.x,self.y
end
end

proc start=
a:=point(10,20)
b:=dirvec(30,30)

a.plot()
b.plot()
end

The output here is:

POINT 10 20
DIRVEC 30 30

Each instance (A and B), contains values for its X and Y fields. But no
pointers to method tables. But they both have, because it is dynamic, is
a type tag: a index into tables of types.

That is used to search (again because its dynamic), a table of entries
for the 'plot' attribute (which can be used in a different other types
too), which matches the types of A and B.

I would have expect a static language to convert those last the lines to:

point.plot(a)
dirvec.plot(b)

I guess it depends on how A and B would be declared, and whether, if
they have those two different types, either can still be passed to a
function taking a Point type, and possibly one taking a Dirvec type.

(I think I ran into trouble trying this in static code, not just because
of methods, but because the two types instances would have the normal
fields at different offsets, and could be different types; say Point has
int32 X,Y, but Dirvec defines float64 Y,Z and inherits int32 X.

But maybe I'm just not understanding how OOP is supposed to work.)

Re: OO object layout - method-table pointer or tag

<sgi9gc$d35$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=632&group=comp.lang.misc#632

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 10:47:55 +0100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <sgi9gc$d35$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Aug 2021 09:47:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f3cbc23dbd01a4b94ff0965a2b8ec696";
logging-data="13413"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1MAUZs9S3mHy7w4/bovgRknjGvv7GLCI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:ay7STY0Xt1TrcHnHvNJDLJVlrDI=
In-Reply-To: <sggnc4$o9c$2@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Mon, 30 Aug 2021 09:47 UTC

On 29/08/2021 20:32, Dmitry A. Kazakov wrote:
> On 2021-08-29 20:24, James Harris wrote:
>
>> Ignoring the length part (as some objects would have their own length
>> and some would not but that difference is immaterial here) how would a
>> 'tag' system be laid out in memory and how would one use that to
>> locate a method?
>
> You must consider the following inheritance variants:

....

Thanks for the information, Dmitry. I might come back to you about some
of that. But for this thread I was wondering how the memory might be
laid out under the tag model that you mentioned. What form does a tag
take and how does the runtime get from the tag to a method?

If it depends on which model is in use then what about single
inheritance and the Full MI model you mentioned?

--
James Harris

Re: OO object layout - method-table pointer or tag

<sgibii$r5q$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=634&group=comp.lang.misc#634

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 11:23:13 +0100
Organization: A noiseless patient Spider
Lines: 141
Message-ID: <sgibii$r5q$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 Aug 2021 10:23:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f3cbc23dbd01a4b94ff0965a2b8ec696";
logging-data="27834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PCYGzuxwLK6/efq5RPq9mn4eUQ5YIhlE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:JEsBo4vrANCotQ8IQm3AbQohHYU=
In-Reply-To: <sgh09l$r5k$1@dont-email.me>
Content-Language: en-GB
 by: James Harris - Mon, 30 Aug 2021 10:23 UTC

On 29/08/2021 23:04, Bart wrote:
> On 29/08/2021 19:24, James Harris wrote:
>> I am a long way from implementing OO-type objects but I have in mind a
>> layout for them and something Dmitry mentioned in another thread
>> suggested that there may be a better way.
>>
>> My intended model is to have each object's data preceded by a pointer
>> to a table of its methods.

....

>>
>> However Dmitry said: "You do not need length, because it can be
>> deduced from the tag. Then tag is more universal than a pointer to the
>> table. Pointer do not work with multiple-dispatch, for example."

....

> I haven't implemented this stuff in static code: classes with methods
> and with inheritance, so can't speak directly from experience.
>
> I have played with it however, and I have implemented it for dynamic code.
>
> The first thing that strikes me, if I understood correctly, is that each
> instance of a Point needs to include not only the data x,y, but also a
> pointer.
>
> With apparently, exactly the same pointer in each of millions of
> instances. Which all means that if you allocate an array of such points,
> you can't just initialise them with all-zeros to (0,0), but need to
> specifically initialise that pointer field in each one.
>
> So, why is that actually necessary? Is it because of inheritance, where
> any instance P could be of the base class, or of a derived class which
> could have its own sets of methods, and this information is not known
> until runtime?

It's not because of inheritance. It's to support polymorphism.

Without OO there would be no 'method table pointer' (MTP). Instead, each
function called to act on an object would know the object's type and,
hence, where its fields are.

With OO the object could be one of a number of different types as long
as they all have the same conceptual set of functions (in the same
internal order), e.g. they both have a plot() function or they both have
an add() function. So you could have

pixel_point P
float_point F

Both types could have a plot() function. As long as it had the same
interface then the function could be invoked by

P.plot()
F.plot()

The key benefit, AISI, is that the routine which calls plot would work
with either type of point. The call wouldn't care what form the point
took; it would be polymorphic.

Of course, whether that's worth the complexity of the implementation is
debatable but it does allow a lot of source code to be simpler.

>
> I can illustrate that with this example in dynamic code:
>
>     record point =
>         var x,y
>         proc plot(&self) =
>             println "POINT",self.x,self.y
>         end
>     end
>
>     record dirvec(point) =        # inherit from Point
>         proc plot(&self) =
>             println "DIRVEC",self.x,self.y
>         end
>     end
>
>     proc start=
>         a:=point(10,20)
>         b:=dirvec(30,30)
>
>         a.plot()
>         b.plot()
>     end
>
> The output here is:
>
>     POINT 10 20
>     DIRVEC 30 30
>
> Each instance (A and B), contains values for its X and Y fields. But no
> pointers to method tables. But they both have, because it is dynamic, is
> a type tag: a index into tables of types.

So your form of a tag is an index into a table? Maybe that's how
Dmitry's 'tag' would be implemented.

I have doubts about indexing into a table rather than pointing to the
method table directly. It would probably require at least one extra
level of dereferencing to find a method.

>
> That is used to search (again because its dynamic), a table of entries
> for the 'plot' attribute (which can be used in a different other types
> too), which matches the types of A and B.
>
> I would have expect a static language to convert those last the lines to:
>
>    point.plot(a)
>    dirvec.plot(b)

Why not

a.plot()
b.plot()

?

>
> I guess it depends on how A and B would be declared, and whether, if
> they have those two different types, either can still be passed to a
> function taking a Point type, and possibly one taking a Dirvec type.
>
> (I think I ran into trouble trying this in static code, not just because
> of methods, but because the two types instances would have the normal
> fields at different offsets, and could be different types; say Point has
> int32 X,Y, but Dirvec defines float64 Y,Z and inherits int32 X.
>
> But maybe I'm just not understanding how OOP is supposed to work.)

Dmitry's reply about various different interpretations of how OOP can
work shows there is no single right answer. Indeed, OOP may not be the
best solution, at all.

--
James Harris

Re: OO object layout - method-table pointer or tag

<sgieru$h01$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=639&group=comp.lang.misc#639

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.brown@hesbynett.no (David Brown)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 13:19:26 +0200
Organization: A noiseless patient Spider
Lines: 204
Message-ID: <sgieru$h01$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 Aug 2021 11:19:27 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="15a0b6fced2eb349af46ab413288d451";
logging-data="17409"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xyT1FgpfMjdOriQfXGDupoih0Zoqnq8Q="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Z8vwcGUOd7F/K+Z8fnVlVNAK4ro=
In-Reply-To: <sgibii$r5q$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Mon, 30 Aug 2021 11:19 UTC

On 30/08/2021 12:23, James Harris wrote:
> On 29/08/2021 23:04, Bart wrote:
>> On 29/08/2021 19:24, James Harris wrote:
>>> I am a long way from implementing OO-type objects but I have in mind
>>> a layout for them and something Dmitry mentioned in another thread
>>> suggested that there may be a better way.
>>>
>>> My intended model is to have each object's data preceded by a pointer
>>> to a table of its methods.
>
> ...
>
>>>
>>> However Dmitry said: "You do not need length, because it can be
>>> deduced from the tag. Then tag is more universal than a pointer to
>>> the table. Pointer do not work with multiple-dispatch, for example."
>
> ...
>
>> I haven't implemented this stuff in static code: classes with methods
>> and with inheritance, so can't speak directly from experience.
>>
>> I have played with it however, and I have implemented it for dynamic
>> code.
>>
>> The first thing that strikes me, if I understood correctly, is that
>> each instance of a Point needs to include not only the data x,y, but
>> also a pointer.
>>
>> With apparently, exactly the same pointer in each of millions of
>> instances. Which all means that if you allocate an array of such
>> points, you can't just initialise them with all-zeros to (0,0), but
>> need to specifically initialise that pointer field in each one.
>>
>> So, why is that actually necessary? Is it because of inheritance,
>> where any instance P could be of the base class, or of a derived class
>> which could have its own sets of methods, and this information is not
>> known until runtime?
>
> It's not because of inheritance. It's to support polymorphism.

In particular, it is for support of run-time polymorphism.

There is also compile-time polymorphism, handled by templates or other
generic coding mechanisms. Since the types are determined entirely at
compile time, there is no need for a pointer to a virtual method table
and like C++ classes without virtual methods, there is no need for the
extra pointer in the class implementation. (Obviously compile-time
polymorphism has limitations of flexibility, but it results in more
efficient code.)

I often use inheritance in C++ without virtual methods, and therefore no
virtual method table overhead in the classes (and no possibility of
run-time polymorphism).

>
> Without OO there would be no 'method table pointer' (MTP). Instead, each
> function called to act on an object would know the object's type and,
> hence, where its fields are.
>
> With OO the object could be one of a number of different types as long
> as they all have the same conceptual set of functions (in the same
> internal order), e.g. they both have a plot() function or they both have
> an add() function. So you could have
>
>   pixel_point P
>   float_point F
>
> Both types could have a plot() function. As long as it had the same
> interface then the function could be invoked by
>
>   P.plot()
>   F.plot()
>
> The key benefit, AISI, is that the routine which calls plot would work
> with either type of point. The call wouldn't care what form the point
> took; it would be polymorphic.
>
> Of course, whether that's worth the complexity of the implementation is
> debatable but it does allow a lot of source code to be simpler.
>

<https://en.wikipedia.org/wiki/Virtual_method_table>

You are describing exactly the system used in many compiled object
oriented languages.

But you should be aware that compile-time polymorphism has become the
current trend, giving more efficient results in many cases.

>>
>> I can illustrate that with this example in dynamic code:
>>
>>      record point =
>>          var x,y
>>          proc plot(&self) =
>>              println "POINT",self.x,self.y
>>          end
>>      end
>>
>>      record dirvec(point) =        # inherit from Point
>>          proc plot(&self) =
>>              println "DIRVEC",self.x,self.y
>>          end
>>      end
>>
>>      proc start=
>>          a:=point(10,20)
>>          b:=dirvec(30,30)
>>
>>          a.plot()
>>          b.plot()
>>      end
>>
>> The output here is:
>>
>>      POINT 10 20
>>      DIRVEC 30 30
>>
>> Each instance (A and B), contains values for its X and Y fields. But
>> no pointers to method tables. But they both have, because it is
>> dynamic, is a type tag: a index into tables of types.
>

That code is not dynamic polymorphism - the types are all statically
known at compile time. Dynamic polymorphism would be if you also had:

proc doubleplot(&x) =
x.plot();
x.plot();
end

proc start =
a : =point(10, 20)
b := dirvec(30, 30)
doubleplot(&a)
doubleplot(&b)
end

i.e., the function "doubleplot" is compiled without knowing whether it
will be calling the "point" version of "plot", or the "dirvec" version.

> So your form of a tag is an index into a table? Maybe that's how
> Dmitry's 'tag' would be implemented.

That's what it sounds like to me. I don't see off-hand any significant
benefits of using an index into a table, rather than a pointer directly
to the type information (primarily the virtual methods list, but perhaps
also containing run-time type information if the language supports taht).

>
> I have doubts about indexing into a table rather than pointing to the
> method table directly. It would probably require at least one extra
> level of dereferencing to find a method.
>

The extra level of indirection could be removed if you are doing
whole-program code generation, but you'd still need to scale the index
and add it to the base of the table instead of using the pointer directly.

>>
>> That is used to search (again because its dynamic), a table of entries
>> for the 'plot' attribute (which can be used in a different other types
>> too), which matches the types of A and B.
>>
>> I would have expect a static language to convert those last the lines to:
>>
>>     point.plot(a)
>>     dirvec.plot(b)
>
> Why not
>
>   a.plot()
>   b.plot()
>
> ?

Perhaps Bart meant the static language would implement "a.plot()" as
though it had been "point.plot(a)", which is exactly how optimising
compilers /do/ implement polymorphism when they know the types at
compile time. (These applies to virtual methods too - it's called
devirtualisation optimisation.)

>
>>
>> I guess it depends on how A and B would be declared, and whether, if
>> they have those two different types, either can still be passed to a
>> function taking a Point type, and possibly one taking a Dirvec type.
>>
>> (I think I ran into trouble trying this in static code, not just
>> because of methods, but because the two types instances would have the
>> normal fields at different offsets, and could be different types; say
>> Point has int32 X,Y, but Dirvec defines float64 Y,Z and inherits int32 X.
>>
>> But maybe I'm just not understanding how OOP is supposed to work.)
>
> Dmitry's reply about various different interpretations of how OOP can
> work shows there is no single right answer. Indeed, OOP may not be the
> best solution, at all.
>

Yes. Your job here is to listen to all the ideas, and figure out what
will work for /you/ and /your/ language.

Re: OO object layout - method-table pointer or tag

<sgifsq$1p16$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=640&group=comp.lang.misc#640

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!Hx95GBhnJb0Xc8StPhH8AA.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 13:36:58 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgifsq$1p16$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="58406"; posting-host="Hx95GBhnJb0Xc8StPhH8AA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Mon, 30 Aug 2021 11:36 UTC

On 2021-08-30 11:47, James Harris wrote:
> On 29/08/2021 20:32, Dmitry A. Kazakov wrote:
>> On 2021-08-29 20:24, James Harris wrote:
>>
>>> Ignoring the length part (as some objects would have their own length
>>> and some would not but that difference is immaterial here) how would
>>> a 'tag' system be laid out in memory and how would one use that to
>>> locate a method?
>>
>> You must consider the following inheritance variants:
>
> ...
>
> Thanks for the information, Dmitry. I might come back to you about some
> of that. But for this thread I was wondering how the memory might be
> laid out under the tag model that you mentioned. What form does a tag
> take and how does the runtime get from the tag to a method?

You must also consider type tests. E.g. is A a descendant of B, unrelated?

> If it depends on which model is in use then what about single
> inheritance and the Full MI model you mentioned?

In the most general case a dispatching table belongs to the method, not
to the type. The tag would denote an N-th coordinate (plane) of the
multidimensional index in the table.

E.g. in the case of full dispatch: Print (Device, Shape), Print is a
method of two hierarchies.

Now, of course, because the same tag must be used to index a multitude
of tables, it cannot be a dense index. So, go figure.

Another issue to consider is whether tables are contiguous. Consider the
following scenario:

The type A is declared in the shared library libA. So you can put the
dispatching table there? Not so fast. Let there be the library libB,
that derives some B from A. That must change the dispatching tables for
A upon loading of libB. When unloading libB you must roll the changes back.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sgihn6$44q$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=644&group=comp.lang.misc#644

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 13:08:02 +0100
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <sgihn6$44q$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 Aug 2021 12:08:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d34df35c3798e2c34a1b8f95ab27c825";
logging-data="4250"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EdxQpqPVmFeSMEORqU72uZGPZZK+hEHw="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:9beC26N6bynIVi1CN+kHov6s9lo=
In-Reply-To: <sgibii$r5q$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210830-0, 30/8/2021), Outbound message
 by: Bart - Mon, 30 Aug 2021 12:08 UTC

On 30/08/2021 11:23, James Harris wrote:
> On 29/08/2021 23:04, Bart wrote:

>> So, why is that actually necessary? Is it because of inheritance,
>> where any instance P could be of the base class, or of a derived class
>> which could have its own sets of methods, and this information is not
>> known until runtime?
>
> It's not because of inheritance. It's to support polymorphism.
>
> Without OO there would be no 'method table pointer' (MTP). Instead, each
> function called to act on an object would know the object's type and,
> hence, where its fields are.
>
> With OO the object could be one of a number of different types as long
> as they all have the same conceptual set of functions (in the same
> internal order), e.g. they both have a plot() function or they both have
> an add() function. So you could have
>
>   pixel_point P
>   float_point F
>
> Both types could have a plot() function. As long as it had the same
> interface then the function could be invoked by
>
>   P.plot()
>   F.plot()
>
> The key benefit, AISI, is that the routine which calls plot would work
> with either type of point. The call wouldn't care what form the point
> took; it would be polymorphic.

That example looks too simple to me; it doesn't really involve OO in my
opinion as it merely provides a convenient alternative syntax. Example
in static code:

record pixelpoint =
byte x,y
proc plot(pixelpoint &self)=
println "Pixelpoint:",self.x,self.y
end
end

record floatpoint =
real x,y
proc plot(floatpoint &self)=
println "Floatpoint:",self.x,self.y
end
end

proc start=
pixelpoint p:=(10,20)
floatpoint q:=(30.5,40.6)

p.plot()
q.plot()
println p.bytes, q.bytes
end

Output is:

Pixelpoint: 10 20
Floatpoint: 30.500000 40.600000
2 16

That p.plot() line is just an alternative to pixelpoint.plot(p), with
the transformation done at compile-time. Here, this is just
encapsulation (which I actually never use; I'm surprised it works!).

I'm not up on OO terms, but polymorphism to me would mean function and
operator overloading. So if you had two functions both called plot,
taking pixelpoint or floatpoint parameters respectively, you could say:

plot(p)
plot(f)

>> Each instance (A and B), contains values for its X and Y fields. But
>> no pointers to method tables. But they both have, because it is
>> dynamic, is a type tag: a index into tables of types.
>
> So your form of a tag is an index into a table? Maybe that's how
> Dmitry's 'tag' would be implemented.

That's just generally how it works with dynamic typing; the tag is the
key to everything. However such code usually means dynamic type dispatch
which is slow. If you have static typing at all, you expect it to be
much faster.

> I have doubts about indexing into a table rather than pointing to the
> method table directly. It would probably require at least one extra
> level of dereferencing to find a method.

Why, in your example, wouldn't the compiler know the type of P?

Do you have a more elaborate example that shows off the advantages of
OO, or whatever you are trying to do, that would be too clunky in C?

Re: OO object layout - method-table pointer or tag

<sgiig5$9k6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=645&group=comp.lang.misc#645

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 13:21:21 +0100
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <sgiig5$9k6$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgieru$h01$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Aug 2021 12:21:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d34df35c3798e2c34a1b8f95ab27c825";
logging-data="9862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195VgXd3kM37u8bmPlekGYv3l04BlobGZk="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:DAjlxErl44F7Fb83XULrAd79wPc=
In-Reply-To: <sgieru$h01$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210830-0, 30/8/2021), Outbound message
 by: Bart - Mon, 30 Aug 2021 12:21 UTC

On 30/08/2021 12:19, David Brown wrote:
> On 30/08/2021 12:23, James Harris wrote:
>> On 29/08/2021 23:04, Bart wrote:

>>> I can illustrate that with this example in dynamic code:

> That code is not dynamic polymorphism - the types are all statically
> known at compile time. Dynamic polymorphism would be if you also had:
>
> proc doubleplot(&x) =
> x.plot();
> x.plot();
> end
>
> proc start =
> a := point(10, 20)
> b := dirvec(30, 30)
> doubleplot(&a)
> doubleplot(&b)
> end
>
> i.e., the function "doubleplot" is compiled without knowing whether it
> will be calling the "point" version of "plot", or the "dirvec" version.

This works fine (but the &s are not needed). But since this is a
dynamically typed language where you get generics and everything else
for free, that is not surprising.

I was making a point about what information needs to be stored with each
instance. Sometimes I don't even need the tag for every point value:

type point = struct
int32 x,y
end

proc start =
x:=new(array,point, 1 million)
println x.bytes
print x[12345]
end

Output is:

8000000
(0,0)

However the 'struct' type doesn't have methods. That is just because the
language decided not to allow that; it could have done, and each array
element would still need only 8 bytes (the array object itself has a tag
and knows the type of the elements).

But it still knows how to print the type! (For a custom print function,
here I'd favour an overload of 'tostring' for this point type, then I
can just do a regular 'print'.)

Re: OO object layout - method-table pointer or tag

<sgijql$ab$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=646&group=comp.lang.misc#646

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!Hx95GBhnJb0Xc8StPhH8AA.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 14:44:05 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgijql$ab$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sgh09l$r5k$1@dont-email.me>
<sgibii$r5q$1@dont-email.me> <sgieru$h01$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="331"; posting-host="Hx95GBhnJb0Xc8StPhH8AA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Mon, 30 Aug 2021 12:44 UTC

On 2021-08-30 13:19, David Brown wrote:

> There is also compile-time polymorphism, handled by templates or other
> generic coding mechanisms.

Yes, but static polymorphism has a very limited use because you cannot
have objects from the closure of the class, only instances of specific
type ones. In practice this precludes most cases of reuse.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sgjesh$dvh$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=660&group=comp.lang.misc#660

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 21:25:53 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <sgjesh$dvh$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Aug 2021 20:25:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f3cbc23dbd01a4b94ff0965a2b8ec696";
logging-data="14321"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dm4uUpVk7HIYIr20s3g8+JZ4toSxHm6s="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:np3g+1SVXRMFZQLeKpHExnnJ+n8=
In-Reply-To: <sgifsq$1p16$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Mon, 30 Aug 2021 20:25 UTC

On 30/08/2021 12:36, Dmitry A. Kazakov wrote:
> On 2021-08-30 11:47, James Harris wrote:
>> On 29/08/2021 20:32, Dmitry A. Kazakov wrote:
>>> On 2021-08-29 20:24, James Harris wrote:
>>>
>>>> Ignoring the length part (as some objects would have their own
>>>> length and some would not but that difference is immaterial here)
>>>> how would a 'tag' system be laid out in memory and how would one use
>>>> that to locate a method?
>>>
>>> You must consider the following inheritance variants:
>>
>> ...
>>
>> Thanks for the information, Dmitry. I might come back to you about
>> some of that. But for this thread I was wondering how the memory might
>> be laid out under the tag model that you mentioned. What form does a
>> tag take and how does the runtime get from the tag to a method?
>
> You must also consider type tests. E.g. is A a descendant of B, unrelated?

Interesting question...!

>
>> If it depends on which model is in use then what about single
>> inheritance and the Full MI model you mentioned?
>
> In the most general case a dispatching table belongs to the method, not
> to the type. The tag would denote an N-th coordinate (plane) of the
> multidimensional index in the table.

That sounds weird. If the dispatch table belongs to the method what
would it be indexed by?

When you talk about a tag do you mean something that might, if it cannot
be optimised any better, result in a series of three or even more
lookups executed at run time before the required method is found?

>
> E.g. in the case of full dispatch: Print (Device, Shape), Print is a
> method of two hierarchies.
>
> Now, of course, because the same tag must be used to index a multitude
> of tables, it cannot be a dense index. So, go figure.
>
> Another issue to consider is whether tables are contiguous. Consider the
> following scenario:
>
> The type A is declared in the shared library libA. So you can put the
> dispatching table there? Not so fast. Let there be the library libB,
> that derives some B from A. That must change the dispatching tables for
> A upon loading of libB. When unloading libB you must roll the changes back.

It's rare that a good idea is so complex or has so many semantically
different implementations. I do wonder whether all this complexity
should be replaced by something simpler.

My current scheme is simpler but it doesn't necessarily have
substitutability which is something I gather you believe to be
important, even from your interesting question, above.

--
James Harris

Re: OO object layout - method-table pointer or tag

<sgjhl6$1mqg$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=663&group=comp.lang.misc#663

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!Hx95GBhnJb0Xc8StPhH8AA.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Mon, 30 Aug 2021 23:13:10 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgjhl6$1mqg$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="56144"; posting-host="Hx95GBhnJb0Xc8StPhH8AA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Mon, 30 Aug 2021 21:13 UTC

On 2021-08-30 22:25, James Harris wrote:
> On 30/08/2021 12:36, Dmitry A. Kazakov wrote:
>> On 2021-08-30 11:47, James Harris wrote:
>>> On 29/08/2021 20:32, Dmitry A. Kazakov wrote:
>>>> On 2021-08-29 20:24, James Harris wrote:
>>>>
>>>>> Ignoring the length part (as some objects would have their own
>>>>> length and some would not but that difference is immaterial here)
>>>>> how would a 'tag' system be laid out in memory and how would one
>>>>> use that to locate a method?
>>>>
>>>> You must consider the following inheritance variants:
>>>
>>> ...
>>>
>>> Thanks for the information, Dmitry. I might come back to you about
>>> some of that. But for this thread I was wondering how the memory
>>> might be laid out under the tag model that you mentioned. What form
>>> does a tag take and how does the runtime get from the tag to a method?
>>
>> You must also consider type tests. E.g. is A a descendant of B,
>> unrelated?
>
> Interesting question...!
>
>>
>>> If it depends on which model is in use then what about single
>>> inheritance and the Full MI model you mentioned?
>>
>> In the most general case a dispatching table belongs to the method,
>> not to the type. The tag would denote an N-th coordinate (plane) of
>> the multidimensional index in the table.
>
> That sounds weird. If the dispatch table belongs to the method what
> would it be indexed by?

By the type, of course. It is pretty straightforward. Consider

Surface Shape
/ \ / \
PDF SVG Ellipse Rectangle

Draw | PDF | SVG |
----------+-----+-----+
Ellipse | ptr | ptr |
----------+-----+-----+
Rectangle | ptr | ptr |
----------+-----+-----+

> When you talk about a tag do you mean something that might, if it cannot
> be optimised any better, result in a series of three or even more
> lookups executed at run time before the required method is found?

Yes. You need some unique type identifier, short enough to fit in a
register.

>> Another issue to consider is whether tables are contiguous. Consider
>> the following scenario:
>>
>> The type A is declared in the shared library libA. So you can put the
>> dispatching table there? Not so fast. Let there be the library libB,
>> that derives some B from A. That must change the dispatching tables
>> for A upon loading of libB. When unloading libB you must roll the
>> changes back.
>
> It's rare that a good idea is so complex or has so many semantically
> different implementations. I do wonder whether all this complexity
> should be replaced by something simpler.

It is a very complex issue. E.g. consider requirements:

1. All slots in a dispatching table are always defined, i.e. dispatch
never fail at run-time.

1.1. That would require the user to override slots the language cannot
safely inherit from the parent type, e.g. mixed type operations.

1.2. The problem with modules. Let the module X derive HTML from Surface
and the module Y derive Sector from Shape. If neither of the modules
uses/knows another, where to define Draw (HTML, Sector)?

There must be some solution for where to place methods. BTW, C++ model
when methods are put into classes is clearly inconsistent with multiple
dispatch. Where to place Draw?

2. No object of a type may exist after the type ceases to exist.

3. Dispatch never happens on partially constructed/destructed objects.
Consider:

A
|
B

In the constructor of B is called after A is constructed. Now what
happens if you dispatch to Foo from the constructor of A and Foo is
overridden by B?

C++ "resolves" that by refusing to dispatch. It will call A::Foo instead
of B::Foo.

That is no solution because programmers do need dispatching
constructors/destructors. A possible solution would be to have
constructors/destructors of class-wide objects where you could safely
dispatch from.

4. Allowing or not to re-dispatch. I.e. if you dispatch on Foo, can you
dispatch again on the same argument inside Foo? This is how C++ works
and this is greatly inefficient and also inconsistent with the types.

> My current scheme is simpler but it doesn't necessarily have
> substitutability which is something I gather you believe to be
> important, even from your interesting question, above.

Inheritance is an open issue. I do not know any language that handles it
consistently and complete. So you have a chance to invent something useful.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sgt4bb$ea7$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=721&group=comp.lang.misc#721

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 13:27:22 +0100
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <sgt4bb$ea7$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Sep 2021 12:27:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0531d7d1b196579145ea507a8ce659ff";
logging-data="14663"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/C5fDoKqJv9wWiB4Yti4jMOpBQ3gdYnKA="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:DcMtDGa44VQXml/LE2k25zoGAZw=
In-Reply-To: <sgjhl6$1mqg$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Fri, 3 Sep 2021 12:27 UTC

On 30/08/2021 22:13, Dmitry A. Kazakov wrote:
> On 2021-08-30 22:25, James Harris wrote:
>> On 30/08/2021 12:36, Dmitry A. Kazakov wrote:

....

>>> In the most general case a dispatching table belongs to the method,
>>> not to the type. The tag would denote an N-th coordinate (plane) of
>>> the multidimensional index in the table.
>>
>> That sounds weird. If the dispatch table belongs to the method what
>> would it be indexed by?
>
> By the type, of course. It is pretty straightforward. Consider
>
>    Surface       Shape
>      /  \         /  \
>    PDF  SVG  Ellipse  Rectangle
>
>    Draw      | PDF | SVG |
>    ----------+-----+-----+
>    Ellipse   | ptr | ptr |
>    ----------+-----+-----+
>    Rectangle | ptr | ptr |
>    ----------+-----+-----+

That solution looks as though the shapes would have to know how to draw
themselves on different surfaces. As such I doubt it would scale well as
new shapes and new types of surface were added. But maybe it's purely
illustrative of multiple dispatch. What I take from it is that, however
it's done, the address of the drawing function (the ptr in the above
table) would need to be found from a key of three parameters

(shape type, surface type, function name)

whereas single dispatch would find a function based on two parameters
such as

(shape type, function name)

Is that correct?

>
>> When you talk about a tag do you mean something that might, if it
>> cannot be optimised any better, result in a series of three or even
>> more lookups executed at run time before the required method is found?
>
> Yes. You need some unique type identifier, short enough to fit in a
> register.

If the tag is the unique identifier you mention how would the compiled
code get from the tag to the correct routine?

My intention was for the tag to be the address of the dispatch table so
that functions (as long as they were at known offsets) could be accessed
quickly but I don't think you liked that.

I will have to come back to you on the other points of your post.

--
James Harris

Re: OO object layout - method-table pointer or tag

<sgt8id$1pbb$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=723&group=comp.lang.misc#723

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 15:39:25 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgt8id$1pbb$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="58731"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Fri, 3 Sep 2021 13:39 UTC

On 2021-09-03 14:27, James Harris wrote:
> On 30/08/2021 22:13, Dmitry A. Kazakov wrote:
>> On 2021-08-30 22:25, James Harris wrote:
>>> On 30/08/2021 12:36, Dmitry A. Kazakov wrote:
>
> ...
>
>>>> In the most general case a dispatching table belongs to the method,
>>>> not to the type. The tag would denote an N-th coordinate (plane) of
>>>> the multidimensional index in the table.
>>>
>>> That sounds weird. If the dispatch table belongs to the method what
>>> would it be indexed by?
>>
>> By the type, of course. It is pretty straightforward. Consider
>>
>>     Surface       Shape
>>       /  \         /  \
>>     PDF  SVG  Ellipse  Rectangle
>>
>>     Draw      | PDF | SVG |
>>     ----------+-----+-----+
>>     Ellipse   | ptr | ptr |
>>     ----------+-----+-----+
>>     Rectangle | ptr | ptr |
>>     ----------+-----+-----+
>
> That solution looks as though the shapes would have to know how to draw
> themselves on different surfaces. As such I doubt it would scale well as
> new shapes and new types of surface were added. But maybe it's purely
> illustrative of multiple dispatch. What I take from it is that, however
> it's done, the address of the drawing function (the ptr in the above
> table) would need to be found from a key of three parameters
>
>   (shape type, surface type, function name)
>
> whereas single dispatch would find a function based on two parameters
> such as
>
>   (shape type, function name)
>
> Is that correct?

Yes, and the surface parameter is then class-wide, i.e. each function
must have to deal with any shape (any instance from the class = class-wide).

>>> When you talk about a tag do you mean something that might, if it
>>> cannot be optimised any better, result in a series of three or even
>>> more lookups executed at run time before the required method is found?
>>
>> Yes. You need some unique type identifier, short enough to fit in a
>> register.
>
> If the tag is the unique identifier you mention how would the compiled
> code get from the tag to the correct routine?

Via the dispatching table indexed by the tag. Tag could not be a dense
index, true, so you would use a hash or binary search instead.

> My intention was for the tag to be the address of the dispatch table so
> that functions (as long as they were at known offsets) could be accessed
> quickly but I don't think you liked that.

Hash functions are pretty quick.

Then again, if you don't repeat C++ and Java error confusing class-wide
and specific types, you would drastically reduce cases when dispatch
ever happens. Most of the code deals with statically known specific
types, ergo, no dispatch (or as some call it, "static dispatch").

Segmented dispatching tables is IMO a bigger problem unless you rebuild
affected dispatching each time you load a library or dynamically create
a new type etc.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sgt9p9$kpo$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=724&group=comp.lang.misc#724

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 14:59:58 +0100
Organization: A noiseless patient Spider
Lines: 115
Message-ID: <sgt9p9$kpo$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Sep 2021 14:00:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="17b68791eedc8b35127461492add731b";
logging-data="21304"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SKI4uI1Vr2s1NVESxkfzUrTAcSZIasCE="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:FwFEWJhKFRICHNg+V0CCjeHQSQU=
In-Reply-To: <sgt4bb$ea7$1@dont-email.me>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210902-4, 2/9/2021), Outbound message
 by: Bart - Fri, 3 Sep 2021 13:59 UTC

On 03/09/2021 13:27, James Harris wrote:
> On 30/08/2021 22:13, Dmitry A. Kazakov wrote:
>> On 2021-08-30 22:25, James Harris wrote:
>>> On 30/08/2021 12:36, Dmitry A. Kazakov wrote:
>
> ...
>
>>>> In the most general case a dispatching table belongs to the method,
>>>> not to the type. The tag would denote an N-th coordinate (plane) of
>>>> the multidimensional index in the table.
>>>
>>> That sounds weird. If the dispatch table belongs to the method what
>>> would it be indexed by?
>>
>> By the type, of course. It is pretty straightforward. Consider
>>
>>     Surface       Shape
>>       /  \         /  \
>>     PDF  SVG  Ellipse  Rectangle
>>
>>     Draw      | PDF | SVG |
>>     ----------+-----+-----+
>>     Ellipse   | ptr | ptr |
>>     ----------+-----+-----+
>>     Rectangle | ptr | ptr |
>>     ----------+-----+-----+
>
> That solution looks as though the shapes would have to know how to draw
> themselves on different surfaces. As such I doubt it would scale well as
> new shapes and new types of surface were added. But maybe it's purely
> illustrative of multiple dispatch.

(The example reminds me of actual drawing code I needed to write in my
applications in the 1990s. The script language included functions such
as a general-purpose one called Plot(), with 8 parameters (many optional
with defaults). The remaining docs are poor but I think they were:

Dest Destination code
D Info specific to a destination
Scan Scan type
View View point
P Drawing element
Clear Whether to clear destination first
Nsegments 1, or build results as multiple hoz bands
Flags Misc

This is for displaying a 3D model, which is represented in P as a
hierarchical tree of drawing elements. There were nearly 50 leaf objects
(including Rectangle and Ellipse!) plus named collections which in a HLL
would correspond to a named function call.

Dest is a code broadly indicating one of Window, Image, Printer/Plotter,
or collections of 3D Face or Lines. Here D might refer to the actual
window, a filename to capture output (eg. EPS print format) etc.

Scan indicates how the data should be processed, with 16 variations,
including Wireframe, Hidden, Shaded, Erase, Highlight, DXF dest, Expand
to lines/faces, ...

View specifies the viewpoint from which the result will be rendered, and
whether it uses perspective projection.

Flags controls many other factors: whether to draw grids or axes, page
outlines ...

OK, the example was clearly a simple one to illustrate some aspects of
how OOP works. But I see such examples using shapes all the time and
find them somewhat annoying.

It gives the impression that OOP can magically solve all the problems
that come up in actual applications, but the reality is always a lot
more complicated.

I'm rather sceptical about what OOP can do, and I have firm views on how
far a language should get involved in matters that should be the concern
of an application.

I also think that, if you really want to use OOP seriously, then you're
quite liable to just end up reinventing C++, as you meet the same
obstacles.)

What I take from it is that, however
> it's done, the address of the drawing function (the ptr in the above
> table) would need to be found from a key of three parameters
>
>   (shape type, surface type, function name)
>
> whereas single dispatch would find a function based on two parameters
> such as
>
>   (shape type, function name)
>
> Is that correct?

The shape should describe the shape itself and nothing else. If you want
to plot it, then extra information is needed:

p.plot(surface_type)

With perhaps that parameter being optional when there is a sensible
default. So here there is single dispatch based on shape type.

Anything else would be difficult to get your head around. If there are M
shape types and N surface types, then you've got MxN methods to write,
but where are you going to write them? Functions are written one after
the other, not in a table!

You might consider introducing overloaded functions, so the plot()
method for Rectangle is split into one each for PDF and SVG. Feature creep.

(My approach as I used was single dispatch - a simple switch - using
common code to reduce complex objects to basic edges, and then using
single dispatch on the 'surface' when drawing those edges.)

Re: OO object layout - method-table pointer or tag

<sgtc5c$847$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=726&group=comp.lang.misc#726

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 15:40:43 +0100
Organization: A noiseless patient Spider
Lines: 116
Message-ID: <sgtc5c$847$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt8id$1pbb$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Sep 2021 14:40:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0531d7d1b196579145ea507a8ce659ff";
logging-data="8327"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18aHvptzdBwXwje/mCK/JiFGUXfhfLEdQE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:x4QTGElAqxNPBLvIFcNLxc3p9kI=
In-Reply-To: <sgt8id$1pbb$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Fri, 3 Sep 2021 14:40 UTC

On 03/09/2021 14:39, Dmitry A. Kazakov wrote:
> On 2021-09-03 14:27, James Harris wrote:
>> On 30/08/2021 22:13, Dmitry A. Kazakov wrote:
>>> On 2021-08-30 22:25, James Harris wrote:
>>>> On 30/08/2021 12:36, Dmitry A. Kazakov wrote:
>>
>> ...
>>
>>>>> In the most general case a dispatching table belongs to the method,
>>>>> not to the type. The tag would denote an N-th coordinate (plane) of
>>>>> the multidimensional index in the table.
>>>>
>>>> That sounds weird. If the dispatch table belongs to the method what
>>>> would it be indexed by?
>>>
>>> By the type, of course. It is pretty straightforward. Consider
>>>
>>>     Surface       Shape
>>>       /  \         /  \
>>>     PDF  SVG  Ellipse  Rectangle
>>>
>>>     Draw      | PDF | SVG |
>>>     ----------+-----+-----+
>>>     Ellipse   | ptr | ptr |
>>>     ----------+-----+-----+
>>>     Rectangle | ptr | ptr |
>>>     ----------+-----+-----+
>>
>> That solution looks as though the shapes would have to know how to
>> draw themselves on different surfaces. As such I doubt it would scale
>> well as new shapes and new types of surface were added. But maybe it's
>> purely illustrative of multiple dispatch. What I take from it is that,
>> however it's done, the address of the drawing function (the ptr in the
>> above table) would need to be found from a key of three parameters
>>
>>    (shape type, surface type, function name)
>>
>> whereas single dispatch would find a function based on two parameters
>> such as
>>
>>    (shape type, function name)
>>
>> Is that correct?
>
> Yes, and the surface parameter is then class-wide, i.e. each function
> must have to deal with any shape (any instance from the class =
> class-wide).

OK. I am now trying to understand what you mean by 'class wide'. Are you
saying that each drawing function would have to be passed the target
surface as a parameter - and that makes surface 'class wide'?

In practice, I'd imagine it's best for 'surfaces' to know how to draw on
themselves and they would export drawing primitives (such as point,
line, curve, rectangle, ellipse etc) which routines can call.

>
>>>> When you talk about a tag do you mean something that might, if it
>>>> cannot be optimised any better, result in a series of three or even
>>>> more lookups executed at run time before the required method is found?
>>>
>>> Yes. You need some unique type identifier, short enough to fit in a
>>> register.
>>
>> If the tag is the unique identifier you mention how would the compiled
>> code get from the tag to the correct routine?
>
> Via the dispatching table indexed by the tag. Tag could not be a dense
> index, true, so you would use a hash or binary search instead.

Are you thinking that to find each function the executable code would
carry out the hash or binary search at run time (if optimisation didn't
remove the need for it)?

My guess is that Python works that way: each name referred to in a
method is subjected to lookup in a series of tables (in something called
Method Resolution Order, MRO) starting with the object and ascending to
each class in the MRO in turn until a matching name is found. But that's
slow.

In compiled code, carrying out a hash lookup or a binary search just to
find which function to call would be faster than Python but still too slow.

>
>> My intention was for the tag to be the address of the dispatch table
>> so that functions (as long as they were at known offsets) could be
>> accessed quickly but I don't think you liked that.
>
> Hash functions are pretty quick.

Hash functions are not fast enough to find a call target! I was/am even
concerned about the extra cost of following a double pointer. Using a
hash table would be slower still.

>
> Then again, if you don't repeat C++ and Java error confusing class-wide
> and specific types, you would drastically reduce cases when dispatch
> ever happens. Most of the code deals with statically known specific
> types, ergo, no dispatch (or as some call it, "static dispatch").

I'm not sure I understand that but if you think C++ and Java got it
wrong do you think Ada got it right and what did it do differently?

>
> Segmented dispatching tables is IMO a bigger problem unless you rebuild
> affected dispatching each time you load a library or dynamically create
> a new type etc.
>

I presume that means when a large dispatch table reaches the limits of
its allocated memory and has to be split.

--
James Harris

Re: OO object layout - method-table pointer or tag

<sgtd86$ftp$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=727&group=comp.lang.misc#727

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 15:59:17 +0100
Organization: A noiseless patient Spider
Lines: 88
Message-ID: <sgtd86$ftp$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt9p9$kpo$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Sep 2021 14:59:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0531d7d1b196579145ea507a8ce659ff";
logging-data="16313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UJK20ZptJMGyUpB2AV4x/Gl5WrIGRYI4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:kAzOuy4Up49El4C+Oub2EaRKeqY=
In-Reply-To: <sgt9p9$kpo$1@dont-email.me>
Content-Language: en-GB
 by: James Harris - Fri, 3 Sep 2021 14:59 UTC

On 03/09/2021 14:59, Bart wrote:
> On 03/09/2021 13:27, James Harris wrote:

....

> OK, the example was clearly a simple one to illustrate some aspects of
> how OOP works. But I see such examples using shapes all the time and
> find them somewhat annoying.

I recently had to take a first look at how I'd want a GUI to work. My
answer was basically sentient widgets which knew how to operate on data
and how to draw themselves. But the drawing would be by graphics
primitives which were provided by the surfaces on which the widgets
wanted to appear. Without having implemented any of this, yet, that
seems to me to be the best approach.

>
> It gives the impression that OOP can magically solve all the problems
> that come up in actual applications, but the reality is always a lot
> more complicated.

OOP has lots wrong with it - including multiple incompatible ways of
realising it.

ADTs, by contrast, are great. Each type comes with its own functions.

Don't throw the ADTs out with the OOP!

>
> I'm rather sceptical about what OOP can do, and I have firm views on how
> far a language should get involved in matters that should be the concern
> of an application.
>
> I also think that, if you really want to use OOP seriously, then you're
> quite liable to just end up reinventing C++, as you meet the same
> obstacles.)

I don't know much about C++ but ending up with similar solutions is
unlikely as its design goals are different.
>
>
>  What I take from it is that, however
>> it's done, the address of the drawing function (the ptr in the above
>> table) would need to be found from a key of three parameters
>>
>>    (shape type, surface type, function name)
>>
>> whereas single dispatch would find a function based on two parameters
>> such as
>>
>>    (shape type, function name)
>>
>> Is that correct?
>
> The shape should describe the shape itself and nothing else. If you want
> to plot it, then extra information is needed:
>
>    p.plot(surface_type)
>
> With perhaps that parameter being optional when there is a sensible
> default. So here there is single dispatch based on shape type.
>
> Anything else would be difficult to get your head around. If there are M
> shape types and N surface types, then you've got MxN methods to write,

Indeed, that's exactly the issue. Better to have the M shapes (or
widgets) use a set of drawing primitives, and have those provided by the
N surface types, IMO.

> but where are you going to write them? Functions are written one after
> the other, not in a table!
>
> You might consider introducing overloaded functions, so the plot()
> method for Rectangle is split into one each for PDF and SVG. Feature creep.
>
> (My approach as I used was single dispatch - a simple switch - using
> common code to reduce complex objects to basic edges, and then using
> single dispatch on the 'surface' when drawing those edges.)
>

Why not say that each surface has to provide a set of primitives that
other programs can use to draw on an instance of that type of surface?

--
James Harris

Re: OO object layout - method-table pointer or tag

<sgteu6$10a3$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=730&group=comp.lang.misc#730

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 17:28:07 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgteu6$10a3$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt9p9$kpo$1@dont-email.me>
<sgtd86$ftp$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="33091"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Fri, 3 Sep 2021 15:28 UTC

On 2021-09-03 16:59, James Harris wrote:

> Why not say that each surface has to provide a set of primitives that
> other programs can use to draw on an instance of that type of surface?

Because that set is open ended. OOP allows you

1. adding new primitives (new shapes)

2. using primitives with new surfaces (inheritance)

All counter proposals are static and do not scale in practice, which is
why OOP is used so widely in large projects regardless any difficulties.
There is simple no other way to do it, economically, there is no other way.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sgtg03$1flf$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=731&group=comp.lang.misc#731

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 17:46:12 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgtg03$1flf$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt8id$1pbb$1@gioia.aioe.org>
<sgtc5c$847$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="48815"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Fri, 3 Sep 2021 15:46 UTC

On 2021-09-03 16:40, James Harris wrote:
> On 03/09/2021 14:39, Dmitry A. Kazakov wrote:
>> On 2021-09-03 14:27, James Harris wrote:
>>> On 30/08/2021 22:13, Dmitry A. Kazakov wrote:
>>>> On 2021-08-30 22:25, James Harris wrote:
>>>>> On 30/08/2021 12:36, Dmitry A. Kazakov wrote:
>>>
>>> ...
>>>
>>>>>> In the most general case a dispatching table belongs to the
>>>>>> method, not to the type. The tag would denote an N-th coordinate
>>>>>> (plane) of the multidimensional index in the table.
>>>>>
>>>>> That sounds weird. If the dispatch table belongs to the method what
>>>>> would it be indexed by?
>>>>
>>>> By the type, of course. It is pretty straightforward. Consider
>>>>
>>>>     Surface       Shape
>>>>       /  \         /  \
>>>>     PDF  SVG  Ellipse  Rectangle
>>>>
>>>>     Draw      | PDF | SVG |
>>>>     ----------+-----+-----+
>>>>     Ellipse   | ptr | ptr |
>>>>     ----------+-----+-----+
>>>>     Rectangle | ptr | ptr |
>>>>     ----------+-----+-----+
>>>
>>> That solution looks as though the shapes would have to know how to
>>> draw themselves on different surfaces. As such I doubt it would scale
>>> well as new shapes and new types of surface were added. But maybe
>>> it's purely illustrative of multiple dispatch. What I take from it is
>>> that, however it's done, the address of the drawing function (the ptr
>>> in the above table) would need to be found from a key of three
>>> parameters
>>>
>>>    (shape type, surface type, function name)
>>>
>>> whereas single dispatch would find a function based on two parameters
>>> such as
>>>
>>>    (shape type, function name)
>>>
>>> Is that correct?
>>
>> Yes, and the surface parameter is then class-wide, i.e. each function
>> must have to deal with any shape (any instance from the class =
>> class-wide).
>
> OK. I am now trying to understand what you mean by 'class wide'.

Class-wide = anything from the members of the class.

> Are you
> saying that each drawing function would have to be passed the target
> surface as a parameter - and that makes surface 'class wide'?

Not only passed, it must accept any surface of any surface type. In
particular it means that it must know the type tag.

> In practice, I'd imagine it's best for 'surfaces' to know how to draw on
> themselves and they would export drawing primitives (such as point,
> line, curve, rectangle, ellipse etc) which routines can call.

I commented on that in another post.

>>>>> When you talk about a tag do you mean something that might, if it
>>>>> cannot be optimised any better, result in a series of three or even
>>>>> more lookups executed at run time before the required method is found?
>>>>
>>>> Yes. You need some unique type identifier, short enough to fit in a
>>>> register.
>>>
>>> If the tag is the unique identifier you mention how would the
>>> compiled code get from the tag to the correct routine?
>>
>> Via the dispatching table indexed by the tag. Tag could not be a dense
>> index, true, so you would use a hash or binary search instead.
>
> Are you thinking that to find each function the executable code would
> carry out the hash or binary search at run time (if optimisation didn't
> remove the need for it)?

https://en.wikipedia.org/wiki/Hash_function

Tag -> 1st Foo's parameter Hash = I1
Tag -> 2nd Foo's parameter Hash = I2
..
Tag -> Nth Foo's parameter Hash = IN

Foo_Table (I1, I2, ... IN) --> Target pointer

There exist multi-dimensional hash techniques which would allow you to
do it in less steps. I do not know how effective they are.

>> Hash functions are pretty quick.
>
> Hash functions are not fast enough to find a call target! I was/am even
> concerned about the extra cost of following a double pointer. Using a
> hash table would be slower still.

Faster than anything the user would have to write otherwise, in order to
emulate dispatch.

Then performance is never a big concern. Safety is. User emulations of
dispatch would be nested if-statements, which are not only significantly
slower O(n), but inherently error-prone and unmaintainable.

>> Then again, if you don't repeat C++ and Java error confusing
>> class-wide and specific types, you would drastically reduce cases when
>> dispatch ever happens. Most of the code deals with statically known
>> specific types, ergo, no dispatch (or as some call it, "static
>> dispatch").
>
> I'm not sure I understand that but if you think C++ and Java got it
> wrong do you think Ada got it right and what did it do differently?

If foo and baz are virtual functions of T then

void foo (T& x)
{
x.baz (); -- Dispatches
}

In Ada

procedure Foo (X : T) is
begin
X.Baz; -- Does not dispatch, the type is established to be T
end Foo;

>> Segmented dispatching tables is IMO a bigger problem unless you
>> rebuild affected dispatching each time you load a library or
>> dynamically create a new type etc.
>
> I presume that means when a large dispatch table reaches the limits of
> its allocated memory and has to be split.

Not large, but consisting of several parts, so that you must linearly
search through all of them.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sgtjb2$vqr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=732&group=comp.lang.misc#732

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 17:43:13 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <sgtjb2$vqr$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt9p9$kpo$1@dont-email.me>
<sgtd86$ftp$1@dont-email.me> <sgteu6$10a3$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Sep 2021 16:43:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="0531d7d1b196579145ea507a8ce659ff";
logging-data="32603"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19I0dYNS8gXkrH/Iaw97Z7sQ2RaiLZX68g="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:aVRQXZZSVJWnEqhk5DJ9007NAMs=
In-Reply-To: <sgteu6$10a3$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Fri, 3 Sep 2021 16:43 UTC

On 03/09/2021 16:28, Dmitry A. Kazakov wrote:
> On 2021-09-03 16:59, James Harris wrote:
>
>> Why not say that each surface has to provide a set of primitives that
>> other programs can use to draw on an instance of that type of surface?
>
> Because that set is open ended. OOP allows you
>
> 1. adding new primitives (new shapes)
>
> 2. using primitives with new surfaces (inheritance)
>
> All counter proposals are static and do not scale in practice, which is
> why OOP is used so widely in large projects regardless any difficulties.
> There is simple no other way to do it, economically, there is no other way.
>

Your example was good in showing multiple dispatch but I'm not so sure
it's a good solution in this case, let alone the only way!

The rights and wrongs of the approach are OT so all I'll say is that M*N
does not scale and that new shapes can be constructed from primitives.

Unless I am missing something the cartesian M*N would be costly and so
even economically, as you mention, I cannot agree that there is no other
way.

--
James Harris

Re: OO object layout - method-table pointer or tag

<sgtlum$fij$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=733&group=comp.lang.misc#733

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 19:27:51 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgtlum$fij$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt9p9$kpo$1@dont-email.me>
<sgtd86$ftp$1@dont-email.me> <sgteu6$10a3$1@gioia.aioe.org>
<sgtjb2$vqr$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="15955"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Fri, 3 Sep 2021 17:27 UTC

On 2021-09-03 18:43, James Harris wrote:
> On 03/09/2021 16:28, Dmitry A. Kazakov wrote:
>> On 2021-09-03 16:59, James Harris wrote:
>>
>>> Why not say that each surface has to provide a set of primitives that
>>> other programs can use to draw on an instance of that type of surface?
>>
>> Because that set is open ended. OOP allows you
>>
>> 1. adding new primitives (new shapes)
>>
>> 2. using primitives with new surfaces (inheritance)
>>
>> All counter proposals are static and do not scale in practice, which
>> is why OOP is used so widely in large projects regardless any
>> difficulties. There is simple no other way to do it, economically,
>> there is no other way.
>>
>
> Your example was good in showing multiple dispatch but I'm not so sure
> it's a good solution in this case, let alone the only way!

Of course it is. Write a program that renders a list of shapes in a
widget in a way that you would not need to modify each time another
developers team creates a new shape or supports another surface.

> The rights and wrongs of the approach are OT so all I'll say is that M*N
> does not scale and that new shapes can be constructed from primitives.

You did not thought it through. A set of primitives supported by all
shapes is already a class. This is exactly what a class of shapes is.
Any client of the class expects to find an implementation of any
primitive in any surface.

Remove the class, you will need to write a new client for each surface.

> Unless I am missing something the cartesian M*N would be costly and so
> even economically, as you mention,

And its existence is a fact of life. Shapes exist, surfaces exist,
drawing exist.

> I cannot agree that there is no other way.

Show the other way to implement and use M*N operations safely.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sgtmv4$rfr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=735&group=comp.lang.misc#735

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 18:44:56 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <sgtmv4$rfr$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt9p9$kpo$1@dont-email.me>
<sgtd86$ftp$1@dont-email.me> <sgteu6$10a3$1@gioia.aioe.org>
<sgtjb2$vqr$1@dont-email.me> <sgtlum$fij$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Sep 2021 17:45:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="17b68791eedc8b35127461492add731b";
logging-data="28155"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/d6GNUxupYvry3CYFybzf1gJ//IBgK7Q="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:zzDpoueUHRVW2Sm5Wo0w2QHHIe8=
In-Reply-To: <sgtlum$fij$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210903-6, 3/9/2021), Outbound message
 by: Bart - Fri, 3 Sep 2021 17:44 UTC

On 03/09/2021 18:27, Dmitry A. Kazakov wrote:
> On 2021-09-03 18:43, James Harris wrote:

>
>> Unless I am missing something the cartesian M*N would be costly and so
>> even economically, as you mention,
>
> And its existence is a fact of life. Shapes exist, surfaces exist,
> drawing exist.
>
>> I cannot agree that there is no other way.
>
> Show the other way to implement and use M*N operations safely.

Say you have an enum type listing M different shapes, and another
listing N different surfaces:

* Create a 2D MxN array H of function pointers

* Populate the table (see below)

* To plot any shape S, call the function H[shape_tag, surface_type]

To populate the table (this is what I can do in my language; probably
it's not possible in Ada or others, it might need external
code-generation, or auxiliary, manually-created tables of available
combinations):

* Write the functions for the combinations of Shape and Surface that are
supported; name the functions according to some agreed format. (These
might be methods; that is just a detail)

* Have an initialisation routine that scans all functions in the program
looking for those that implement the plotting (it will look at the name)

* For each such function, extract the shape X and surface Y it
implements, from the name. Fill in H[X,Y] with a reference to the function

* For all table entries not yet populated, fill in a reference to an
error-handler or default-handling function. 'nil' is not recommended!

Re: OO object layout - method-table pointer or tag

<sgtnu2$1bhn$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=736&group=comp.lang.misc#736

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 20:01:39 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sgtnu2$1bhn$1@gioia.aioe.org>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt9p9$kpo$1@dont-email.me>
<sgtd86$ftp$1@dont-email.me> <sgteu6$10a3$1@gioia.aioe.org>
<sgtjb2$vqr$1@dont-email.me> <sgtlum$fij$1@gioia.aioe.org>
<sgtmv4$rfr$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="44599"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Fri, 3 Sep 2021 18:01 UTC

On 2021-09-03 19:44, Bart wrote:
> On 03/09/2021 18:27, Dmitry A. Kazakov wrote:
>> On 2021-09-03 18:43, James Harris wrote:
>
>>
>>> Unless I am missing something the cartesian M*N would be costly and
>>> so even economically, as you mention,
>>
>> And its existence is a fact of life. Shapes exist, surfaces exist,
>> drawing exist.
>>
>>> I cannot agree that there is no other way.
>>
>> Show the other way to implement and use M*N operations safely.
>
> Say you have an enum type listing M different shapes, and another
> listing N different surfaces:
>
> * Create a 2D MxN array H of function pointers

Failed. The requirement included different teams of developers and
different times rows and columns (types) added.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: OO object layout - method-table pointer or tag

<sgtv95$m1s$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=737&group=comp.lang.misc#737

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: OO object layout - method-table pointer or tag
Date: Fri, 3 Sep 2021 21:06:49 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <sgtv95$m1s$1@dont-email.me>
References: <sggjdi$trv$1@dont-email.me> <sggnc4$o9c$2@gioia.aioe.org>
<sgi9gc$d35$1@dont-email.me> <sgifsq$1p16$1@gioia.aioe.org>
<sgjesh$dvh$1@dont-email.me> <sgjhl6$1mqg$1@gioia.aioe.org>
<sgt4bb$ea7$1@dont-email.me> <sgt9p9$kpo$1@dont-email.me>
<sgtd86$ftp$1@dont-email.me> <sgteu6$10a3$1@gioia.aioe.org>
<sgtjb2$vqr$1@dont-email.me> <sgtlum$fij$1@gioia.aioe.org>
<sgtmv4$rfr$1@dont-email.me> <sgtnu2$1bhn$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Sep 2021 20:07:01 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="17b68791eedc8b35127461492add731b";
logging-data="22588"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19LxYEwey9H/fs0qQ6l3CMTgKVnHnDwQ+M="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:uYgh/Kw6wJG8C/S50ZgI7JuxTP0=
In-Reply-To: <sgtnu2$1bhn$1@gioia.aioe.org>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 210903-8, 3/9/2021), Outbound message
 by: Bart - Fri, 3 Sep 2021 20:06 UTC

On 03/09/2021 19:01, Dmitry A. Kazakov wrote:
> On 2021-09-03 19:44, Bart wrote:
>> On 03/09/2021 18:27, Dmitry A. Kazakov wrote:
>>> On 2021-09-03 18:43, James Harris wrote:
>>
>>>
>>>> Unless I am missing something the cartesian M*N would be costly and
>>>> so even economically, as you mention,
>>>
>>> And its existence is a fact of life. Shapes exist, surfaces exist,
>>> drawing exist.
>>>
>>>> I cannot agree that there is no other way.
>>>
>>> Show the other way to implement and use M*N operations safely.
>>
>> Say you have an enum type listing M different shapes, and another
>> listing N different surfaces:
>>
>> * Create a 2D MxN array H of function pointers
>
> Failed. The requirement included different teams of developers and
> different times rows and columns (types) added.
>

How is that relevant? Presumably all the necessary information (method
definitions or their interfaces) will be visible to the (presumably AOT)
compiler when the application is built?

Then who cares who wrote it or when.

Anyway who are you to say how my application will be organised.

Pages:123456
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor