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-Thread: 103376,fc52c633190162e0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!tiscali!newsfeed1.ip.tiscali.net!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsinpeer00.lnd.ops.eu.uu.net!bnewsinpeer00.bru.ops.eu.uu.net!emea.uu.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: why learn C? From: Georg Bauhaus In-Reply-To: <1175499821.557815.303270@y80g2000hsf.googlegroups.com> References: <1172144043.746296.44680@m58g2000cwm.googlegroups.com> <1172161751.573558.24140@h3g2000cwc.googlegroups.com> <546qkhF1tr7dtU1@mid.individual.net> <5ZULh.48$YL5.40@newssvr29.news.prodigy.net> <1175215906.645110.217810@e65g2000hsc.googlegroups.com> <1175230352.808212.15550@e65g2000hsc.googlegroups.com> <1175236212.771445.135460@y66g2000hsf.googlegroups.com> <1175308871.266257.77460@e65g2000hsc.googlegroups.com> <1175499821.557815.303270@y80g2000hsf.googlegroups.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-ID: <1175511246.9702.24.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Date: Mon, 02 Apr 2007 12:54:06 +0200 Organization: Arcor NNTP-Posting-Date: 02 Apr 2007 12:49:40 CEST NNTP-Posting-Host: 6472bb89.newsspool4.arcor-online.net X-Trace: DXC=>dDnJDZno?4T2Rfi6 On Mon, 2007-04-02 at 00:43 -0700, kevin cline wrote: > On Mar 30, 9:41 pm, "jimmaureenrog...@worldnet.att.net" > > type My_Int is range -10..10; > > > > You can provide run time checking in any language. In C++ you would > > need to define a class for My_Int. > > Actually, you would define a template class RangedInt, and then write > something like: > > typedef RangedInt<-10,10> My_Int; > > > The assignment operator would need > > to be re-defined to check for the range, and throw an exception when > > the range limits are violated. > > Right. One eight-line class to replicate the Ada ranged integer type. I'd add a few more lines to a RangedInt in order to have iteration support, explicit range test, 'Valid, using integer operations with compatible subtypes, computing in the base type, and having template compile/link time checks for array-style data structures built on top of the type properties of RangedInt. (Type casts?) And then, unfortunately, C++ doesn't have dynamic types (unless I'm missing something): template int foo(int n) { typedef class RangedInt Int; Int x(12); // ... return *x; } Int would have to be visible only from within foo(), its values would have to be bound by n. Objects of type Int would only exist within foo, and be accessible while foo executes (no & allowed). With Ada 2005, this is true of all locally extensible types. But OTOH, is there any good reason to replace the handful of machine oriented base types that C++ has (inherited from C) and instead use something that is more predictable and more expressive? I think, yes, when apparently students can do their homework significantly more successfully when they can choose names, values, named values and types in the ways that have inspired the Ada type system. (According at least to a seemingly unbiased report presented here some weeks ago, about an embedded systems class.)