comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank J. Lhota" <NOSPAM.lhota.adarose@verizon.net>
Subject: Re: Imitation is the sincerest form of flattery
Date: Tue, 25 Mar 2003 15:53:38 GMT
Date: 2003-03-25T15:53:38+00:00	[thread overview]
Message-ID: <6Y_fa.5102$kU.534@nwrdny01.gnilink.net> (raw)
In-Reply-To: 5115eb96.0303242148.57027600@posting.google.com

"Amir Yantimirov" <amir@iae.nsk.su> wrote in message
news:5115eb96.0303242148.57027600@posting.google.com...

> Not that. I propose something alike this:
>
> type TFoo = record ... end record;
>
> procedure Bar ( Baz : in out TFoo);
>   with TFoo:
>     'First = 1;
>     'Last = 32;
>     [].Read = ReadBits;
>     [].Write = WriteBits;
>   end with;
> begin
>   Baz[40] := 0; -- compile error!

I'm a little confused by this pseudo-code. Is Bar a derived type? Is it some
sort of constructor? And what does the "[].Write = WriteBits;" statement do?
You may very well have a quite valuable idea here, but this code sample does
not convey it. Now that you have piqued our curiousity, please clarify.

> Different levels of abstraction needs different solutions. So I argue
> only that ALL types should be tagged.

In a sense, you're absolutely right. The most consistent way to do OOP is to
allow a type hierarchy to be based on any type, including built-in scalar
types. An example of this is the Smalltalk language. Everything in Smalltalk
is part of a class hierarchy, including boolean values, integers,
characters, and even blocks of code. Smalltalk's consistent "everything is
an object" approach is elegant and provides unparalleled ability to apply
OOP techniques.

There is only one good reason, why Ada, C++, C# and Java have not adapted
the Smalltalk philosophy of having everything tagged: efficiency. Smalltalk,
for all of its virtues, has been terribly slow due to its need to use
indirection for nearly everything. Consider this:

    type My_Integer is new Integer;
    function "+" ( Left, Right : in My_Integer ) return My_Integer;
    function "*" ( Left, Right : in My_Integer ) return My_Integer;
    -- ...

    -- Currently not valid Ada, but this would be valid if Integer is
tagged.
    procedure Compute( A, B : in Integer'Class ) is
    begin
        -- ...
    end Compute;

Within Compute, arithmetic with A and B will depend on whether they are
Integer or My_Integer. As desirable as this may be, this certainly rules out
using the implicit versions of "+" and "*". A call to Compute would require
that, somehow, tags be attached to A and B. This requirement is why we have
the annoying boxing and unboxing stuff in C#.

If there is a way to get the effect of tagged scalar types without a big hit
on efficiency, however, it would certainly be helpful. Perhaps there is some
happy compromise between Smalltalk and C#.





  reply	other threads:[~2003-03-25 15:53 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-14 17:22 Imitation is the sincerest form of flattery Robert C. Leif
2003-03-14 17:57 ` Warren W. Gay VE3WWG
2003-03-14 18:16 ` chris.danx
2003-03-14 18:17 ` Hyman Rosen
2003-03-15 14:18   ` Georg Bauhaus
2003-03-16  1:06     ` Hyman Rosen
2003-03-18 10:37       ` Georg Bauhaus
2003-03-18 15:34         ` Dmitry A. Kazakov
2003-03-19 11:12           ` Georg Bauhaus
2003-03-20  8:42             ` Dmitry A. Kazakov
2003-03-20 14:27               ` Frank J. Lhota
2003-03-21  8:44                 ` Dmitry A. Kazakov
2003-03-21 17:16                   ` Pascal Obry
2003-03-22  9:05                     ` Dmitry A. Kazakov
2003-03-22 14:11                       ` Pascal Obry
2003-03-22 23:12                         ` AG
2003-03-23  9:01                           ` Dmitry A. Kazakov
2003-03-23  8:51                         ` Dmitry A. Kazakov
2003-03-24 16:52                           ` Hyman Rosen
2003-03-24 18:10                             ` Dmitry A. Kazakov
2003-03-24 18:33                               ` Hyman Rosen
2003-03-25  5:04                                 ` Amir Yantimirov
2003-03-25 19:55                                 ` Dmitry A. Kazakov
2003-03-25 20:22                                   ` Hyman Rosen
2003-03-26 13:02                                     ` Dmitry A. Kazakov
2003-03-26 15:06                                       ` Hyman Rosen
2003-03-26 16:21                                         ` Dmitry A. Kazakov
2003-03-26 17:00                                           ` Hyman Rosen
2003-03-26 18:21                                             ` Bill Findlay
2003-03-26 18:40                                               ` Hyman Rosen
2003-03-22 10:01                   ` Amir Yantimirov
2003-03-23  8:41                     ` Dmitry A. Kazakov
2003-03-24  4:53                       ` Amir Yantimirov
2003-03-24 18:10                         ` Dmitry A. Kazakov
2003-03-25  5:48                           ` Amir Yantimirov
2003-03-25 15:53                             ` Frank J. Lhota [this message]
2003-03-25 16:44                               ` Robert A Duff
2003-03-25 18:24                                 ` Frank J. Lhota
2003-03-25 20:06                                   ` Dmitry A. Kazakov
2003-03-27 19:45                                     ` Frank J. Lhota
2003-03-27 21:25                                       ` Pascal Obry
2003-03-28 13:34                                       ` Dmitry A. Kazakov
2003-04-01 14:38                                         ` Frank J. Lhota
2003-04-02  7:37                                           ` Dmitry A. Kazakov
2003-03-26  7:48                                 ` Amir Yantimirov
2003-03-26 13:35                                   ` Dmitry A. Kazakov
2003-03-26  7:32                               ` Amir Yantimirov
2003-03-20 23:28               ` Matthew Heaney
2003-03-21  8:49                 ` Dmitry A. Kazakov
2003-03-21 21:07                   ` Georg Bauhaus
2003-03-22  9:04                     ` Dmitry A. Kazakov
2003-03-22 10:05                       ` AG
2003-03-22 15:25                         ` Georg Bauhaus
2003-03-22 19:27                           ` AG
2003-03-22 21:45                             ` Vinzent Hoefler
2003-03-22 22:28                               ` AG
2003-03-23 23:47                     ` Robert A Duff
2003-03-28 16:34                       ` Georg Bauhaus
2003-03-18 15:58         ` Hyman Rosen
2003-03-19 11:05           ` Georg Bauhaus
2003-03-23 11:31       ` Florian Weimer
2003-03-23 23:39         ` Hyman Rosen
2003-03-15 12:52 ` Florian Weimer
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox