From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,604e0f87aa06eab6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-25 11:54:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!dialin-145-254-049-093.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Imitation is the sincerest form of flattery Date: Tue, 25 Mar 2003 20:55:55 +0100 Organization: At home Message-ID: References: <1047665830.579605@master.nyc.kbcfp.com> <7eee7v4hpvj0i5s345uonlen5315rhiau8@4ax.com> <4dkea.75440$gi1.38045@nwrdny02.gnilink.net> <1048524746.273345@master.nyc.kbcfp.com> <1048530794.5794@master.nyc.kbcfp.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-049-093.arcor-ip.net (145.254.49.93) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: fu-berlin.de 1048622042 79364349 145.254.49.93 (16 [77047]) User-Agent: KNode/0.7.1 Xref: archiver1.google.com comp.lang.ada:35694 Date: 2003-03-25T20:55:55+01:00 List-Id: 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