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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,45b47ecb995e7a3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-13 08:47:38 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!news.tele.dk!small.news.tele.dk!148.122.208.68!news2.oke.nextra.no!nextra.com!news1.oke.nextra.no.POSTED!not-for-mail Sender: ohk@maestro.clustra.com Newsgroups: comp.lang.ada Subject: Re: Ada Idioms Progress Preview References: <3B6F1B2F.4FC3C833@gsde.hou.us.ray.com> <5ee5b646.0108071819.6e84e33d@posting.google.com> <3_Xc7.45$NM5.84779@news.pacbell.net> From: Ole-Hjalmar Kristensen Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 194.143.59.98 X-Complaints-To: news-abuse@nextra.no NNTP-Posting-Date: Mon, 13 Aug 2001 17:46:58 MET DST Organization: Nextra Public Access X-Trace: readme.online.no 997717619 194.143.59.98 Date: 13 Aug 2001 17:47:30 +0200 Xref: archiver1.google.com comp.lang.ada:11856 Date: 2001-08-13T17:47:30+02:00 List-Id: Ted Dennison writes: > In article <3_Xc7.45$NM5.84779@news.pacbell.net>, Jay Nabonne says... > > > >useful for me - and it's what I thought of when I saw the word idiom - is > >something that says "in order to do , given that there's more than one > >way to do it within the Ada language, here's how you write code that looks > >like an Ada programmer wrote it and doesn't look like a > >C++-programmer-writing-Ada wrote it.". > > > >I'm interested in how to "think in Ada"... > > The best advice I can give you today is to go to the Ada Source Code Treasury at > http://www.adapower.com/adacode.html . The master site itself is useful too. > > Based on my experience with native C speakers, here are some basic things to get > you started: > > o Strings in Ada are *very* different from Strings in C. Ada strings end at the > end of the array (or slice of it you specify), not at some arbitrarily-chosen > "terminator" character. Look into the "&" operator for arrays, and the array > attributes 'length, 'first, and 'last. 'image is damn nice too. Don't be > discouraged if you have trouble with this seemingly simple thing. Conceptually, > this is probably the biggest difference the languages have. One thing which can be said in favour of having a terminator character is that it frees you from having to store the length explicitly. The length of a string is usually different from the size of the array used to store the string. So, in a sense a C string is more self-describing than a plain Ada string. Of course, as soon as you call a procedure, you can use a slice, but you still need the actual length to decide which slice. On the balance, I would rather have Ada strings. > > o The techniques you learn for dealing with strings can be used for *all* > arrays. > > o Make yourself familiar with the language defined attributes ( > http://www.ada-auth.org/~acats/arm-html/RM-K.html ). > > o Passing a large data structure as a parameter does *not* mean that the whole > thing gets copied. The compiler will internally pass a reference to the > structure if that would be more efficient. Do *not* use pointers yourself to > force this effect. > > o You almost never need pointers. > > o If you think you need a pointer, see the previous point. :-) > > --- > T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html > home email - mailto:dennison@telepath.com -- Kabelsalat ist gesund. Ole-Hj. Kristensen