comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Imitation is the sincerest form of flattery
Date: Tue, 25 Mar 2003 20:55:55 +0100
Date: 2003-03-25T20:55:55+01:00	[thread overview]
Message-ID: <b5qc4p$2bm07t$1@ID-77047.news.dfncis.de> (raw)
In-Reply-To: 1048530794.5794@master.nyc.kbcfp.com

Hyman Rosen wrote:

> Dmitry A. Kazakov wrote:
>> First of all, there is no contract. I want the compiler be
>  > aware that it is going to be an array and check if it is.
> 
> You have proxy classes that deal with all of this stuff.
> Everything is typechecked.

The type is checked, not the class. It is same as in case of the formal 
parameters generics. That discussion we already had.

>> Secondly to make A[i]=X working you have to use a reference. Now, let I a
>> have a packed bit array. What would be a reference to a bit? You would
>> need to build a fat pointer class to fix this. The array has to represent
>> an image in the video buffer. It has to be damn FAST. And where are
>> multidimensional arrays in C++? And where are slices? Well, for them we
>> need another class, etc. And what if A is a hash table, sparse array. It
>> would be monstrous. And I want it on the stack!
> 
> It's not monstrous at all. First of all, as an Ada programmer,
> you should not be complaining about having to write extra lines
> of code to do what you want, as long as its all nice and readable.

I would complain. I do not like extra lines, especially any helper classes. 
Array is an old well known concept, which requires no baroque kinks.

> Second of all, just because you need classes to handle all of this
> doesn't prevent things from being on the stack, or from being fast.

Right, but not in C++, which is unable to handle unconstrained objects on 
the stack.

> Third of all, there is plenty of existing code to do this sort of
> thing, in Boost and elsewhere.
> 
> Remembering some of our previous threads, I would caution you that
> the proper way to implement all of this will eschew inheritance and
> use templates heavily. If you try to do this using OO, then yes,
> your code will be miserably slow.

But as you said it should not be slow.

>> IMO. The idea of treating
>>     A[i]=X;
>> as
>>     Assign (Index (A, i), X);
>> is a wrong one.
> 
> Why? In particular, this technique is used very often in C++,
> especially with expression templates. One has Index(A,i) just
> return a proxy class which holds A and i, and implements the
> Assign to take such a class. Inline expansion does the rest,
> usually resulting in code that looks like an open-coded version.

Even if this could work as expected, then why the compiler cannot do all 
that to me? But it does not work. If you want to pass an element as an 
in-out parameter (remember Ada has them), your nasty proxy class will show 
itself. Then to reconcile this with LSP you will have to make it derived 
from the type of the element. Ooch ... And this was supposed to be ADT, not 
OO!

--
Regards,
Dmitry A. Kazakov
www.dmitry-kazakov.de



  parent reply	other threads:[~2003-03-25 19:55 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 [this message]
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
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