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-Thread: 103376,2a34b7ad6c6a0774 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Efficiency of code generated by Ada compilers Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8349c981-4dca-49dc-9189-8ea726234de3@f42g2000yqn.googlegroups.com> Date: Tue, 10 Aug 2010 17:32:53 +0200 Message-ID: <12a7fe99uwk7a$.14c2n1hl3aqwk.dlg@40tude.net> NNTP-Posting-Date: 10 Aug 2010 17:32:53 CEST NNTP-Posting-Host: c206b563.newsspool4.arcor-online.net X-Trace: DXC=3@N7aa_;Y?Mk:C4l9A;OcO4IUK67Cdc?2D[6LHn;2LCVN[ On Tue, 10 Aug 2010 06:52:21 -0700 (PDT), Elias Salom�o Helou Neto wrote: > So I am asking very precisely: > does Ada allow me to do non range-checked access to arrays? Yes, in many ways. Others have pointed out how to suppress checks. I would rather advise you to write programs so that the compiler would omit them. Consider this: type Vector is array (Positive range <>) of Long_Float; function Sum (X : Vector) return Long_Float; Implementation: function Sum (X : Vector) return Long_Float is Result : Long_Float := 0.0; begin for Index in X'Range loop Result := Result + X (Index); end loop return Result; end Sum; Since the compiler knows that Index is in X'Range, you told it that, it will generate no subscripts checks. > This is what attracted me, but, as you may guess, I cannot spend > months learning the language if I am not sure about some very specific > issues, such non RC array indexing. Ada arrays are simple and intuitive. And there are multidimensional arrays too. They certainly do not require months to learn. >>> Also, I do need to have something similar to C++ "templated >>> metaprogramming" techniques. >> >> Ada has generics which are roughly same as templates. Unlikely to C+ >> generics are contracted and not automatically instantiated. > > What exactly does it mean? Is it something like run-time > instantiation? It means that the formal parameters of the generics have contracts = typed. C++ template parameters are untyped. You can substitute anything as long as the result compiles. > Hum... I intend to write an efficient n-dimensional matrix. What's wrong with an n-dimensional array? > This would > leave to me the option to individually write element accessing code > for each possible instance of my generic class if I wish to make it > through a member function (or whatever is equivalent to that in Ada) > that takes as many elements as there are dimensions, right? I cannot imagine generic/templated code for an nD matrix package, because it would not allow you to unroll the nested loops over n, if we took an implementation of "+" as an example. It becomes much, much worse for multiplication. I doubt it were a realistic goal to have it generic over n, you will need a more powerful preprocessor than templates. >>> And further, is there any language which is >>> _truly_ better (regarding code maintainability, readability and >>> developing ease) than C++ and as overhead-free as it? >> >> Maintainability, readability and developing ease are sufficiently dependent >> on *not* using things like C++ templates. Even more variadic templates! > > Could you elaborate on that? I do not agree and I do have lots of > experience in writing and maintaining template code in C++. They are > as easy to read, maintain and develop as any C++ code, or should I say > as difficult? Honestly, you are the first I met who considered templates easy to read and maintain. So I am not really prepared to argue. It is like someone said that warm beer is great. How do you test a template class? How do you make it work for Borland C++, MSVC 3, 5, 8, 10 and gcc? When you get an error message whom do you ask what's wrong? >> Note that for numeric applications templates do not help much. Consider the >> following problem. Let you have to implement some mathematical function of >> known algorithm and put it into a library. That latter is not possible with >> templates anyway is beside the point. > > You seem to imply that templated code cannot be part of a library, but > it definitely can. Just consider the possibility of distributing the > source, which is what I wish to do. STL does just that. So, how are you going to test it? We have to maintain our own template library. It is 10 years old, and errors keep on coming because the number of combinations needed to check is impossible to cover. So the maintenance looks like: change the code and commit. If someone gets a problem upon instantiation let us know. BTW, Ada geneircs are much better, because of their contracts, they are compiled in true sense of this word. > Even if you do > not want to go open source, it is easier to write the code once and > instantiate it for every type your users are supposed to use, maybe > wrapped within some overloaded function. We were talking about a n-D matrix package. You suggest to instantiate it for each possible combination of types for each n? (:-)) > It sounds like a > good idea, specially if things like that could be done for user > defined types, i.e., if I can define my own type that "is digits <>". Yes you can. E.g.: type My_Float is digits 8 range -1.0E10..1.0E10; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de