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=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a02:3509:: with SMTP id k9-v6mr7865447jaa.35.1530385671584; Sat, 30 Jun 2018 12:07:51 -0700 (PDT) X-Received: by 2002:aca:c6ca:: with SMTP id w193-v6mr1848237oif.1.1530385671419; Sat, 30 Jun 2018 12:07:51 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!d7-v6no1591579itj.0!news-out.google.com!p13-v6ni2491itf.0!nntp.google.com!u78-v6no1571093itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 30 Jun 2018 12:07:51 -0700 (PDT) In-Reply-To: <856189aa-fa00-4960-929e-174f352310ad@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=47.185.195.62; posting-account=zwxLlwoAAAChLBU7oraRzNDnqQYkYbpo NNTP-Posting-Host: 47.185.195.62 References: <856189aa-fa00-4960-929e-174f352310ad@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1bd0ac50-7e70-41be-aa16-a3e7d30461e6@googlegroups.com> Subject: Re: Teaching C/C++ from Ada perspective? From: "Dan'l Miller" Injection-Date: Sat, 30 Jun 2018 19:07:51 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:53482 Date: 2018-06-30T12:07:51-07:00 List-Id: On Saturday, June 30, 2018 at 1:04:30 PM UTC-5, koua...@gmail.com wrote: > Hello, >=20 > Ada is my programming language of choice. I have used it much in scientif= ic programming. At an University I am asked to teach programming but in C a= nd C++ to fist year students. After having spent some years with Ada, I'm r= elecutant to "throw away" my good programming habits from Ada and embrace C= /C++. I would like to know if there exist(s) good book(s) at introductory l= evel for C/C++ that may go in the spirit of Ada so that I won't feel wastin= g my time and energy teaching C/C++? >=20 > Also I will start the above course with Algorithms in which I have little= knowledge. Any suggestions for good books on this topic? >=20 >=20 > Thank you. >=20 > Kouaoua Short answer: purge as close to 100% of your usage of C semantics from you= r C++ code. Long answer: Well, if you are really really wanting to do this, you would write a whole = bunch of class templates to displace every usage of C-semantics stuff. You= would start with C-semantics scalar types; replace them wholesale. You wo= uld then progress onward to C-semantics typedefs; replace then wholesale wi= th struct-wrapped templates. You would then progress onward to making a be= fore-after list of all C-semantics C++ language constructs to never ever ut= ilize (the before column in the table) followed by the corresponding replac= ement in the modern C++ standard library. You would then extend your table= to also have before-after list of all C-semantics idioms to never ever uti= lize (the before column in the table) followed by the corresponding replace= ment in the modern C++{11,14,17} idioms. When writing wholesale replacements for C-semantics scalar data, you would = go chapter by chapter through the Ada _LRM_ and design Ada-esque =E2=80=98l= anguage design=E2=80=99 utilizing C++ templates of every single C-semantics= topic. 1) Every time that you would otherwise write {int, short, long, signed, uns= igned, float, double, char, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, = int16_t, int32_t, int64_t, any combination/permutation thereof}, you would = instead write ::Adaesque::Integer< _LowerBound_, _UpperBound_ > as the Ada-= esque replacement in C++ for the lack of subtype constraints. 2) Every time that you would otherwise write one of the C-isms in the =E2= =80=98before=E2=80=99 column of the table, you would instead utilize the Ad= a-esque idioms in the =E2=80=98after=E2=80=99 column of the table. 3) You would utilize C++ allocators to emulate Ada-esque pools and subpools= . 4) You would utilize C++{11,14,17,20} concurrency library content and/or la= nguage primitives to emulate Ada tasking. Wholesale replacement of C++'s scalar types with class template replacement= s is first explored in =C2=A75 of Chapter 16 of Barton & Nackman's _Scienti= fic and Engineering C++: An introduction with advanced techniques and examp= les_ (1993). This was done for adding physical-units dimensions to C++; yo= ur motivation is analogous but endorsing Ada instead of SI as the philosoph= ical projection onto C++. This was then developed further by Walter Brown = at Fermi Lab and presented to the C++ standardization committee during 2002= . AIUI, that Fermi Lab work fed into Boost Units library: https://www.boost.org/doc/libs/1_37_0/doc/html/boost_units.html Here is another treatment of the topic by Scott Meyers, much the same as Ba= rton & Nackman's: http://se.ethz.ch/~meyer/publications/OTHERS/scott_meyers/dimensions.pdf In other words, your coursework would not be the first programming culture = to jettison C-semantics baggage from C++, replacing it wholesale with class= template replacements. Hmmmm, the more that I think about this, the more that I think that this wo= uld be an outreach mechanism to draw C++ programmers into Ada: get them to= start programming in Ada-esque concepts as close to 100% of the time while= still remaining in C++.