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:a24:5dd4:: with SMTP id w203-v6mr3795276ita.27.1530557537645; Mon, 02 Jul 2018 11:52:17 -0700 (PDT) X-Received: by 2002:aca:1a18:: with SMTP id a24-v6mr2932953oia.5.1530557537439; Mon, 02 Jul 2018 11:52:17 -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-v6no3263270itj.0!news-out.google.com!z3-v6ni2770iti.0!nntp.google.com!u78-v6no3230592itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 2 Jul 2018 11:52:17 -0700 (PDT) In-Reply-To: <39fce60c-9f56-42fb-b679-fa08810b00ee@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> <2718c8d4-5f35-4fd8-a1aa-1e60069a7a5d@googlegroups.com> <39fce60c-9f56-42fb-b679-fa08810b00ee@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <3701bf07-89a5-4cb0-a704-5aebb589ca79@googlegroups.com> Subject: Re: Teaching C/C++ from Ada perspective? From: "Dan'l Miller" Injection-Date: Mon, 02 Jul 2018 18:52:17 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader02.eternal-september.org comp.lang.ada:53516 Date: 2018-07-02T11:52:17-07:00 List-Id: On Monday, July 2, 2018 at 12:56:43 AM UTC-5, Maciej Sobczak wrote: > > Oh, so the take-away is: > [...] >=20 > Nothing of what you wrote is a take-away, because I did not write any of = this. And I quote from you below, emphasizing the recommendation to teach =E2=80= =A2classes=E2=80=A2, =E2=80=A2namespaces=E2=80=A2, and C++ =E2=80=A2standar= d-library* (oh, sorry, =E2=80=A2encapsulation=E2=80=A2 and =E2=80=A2templat= es=E2=80=A2 too, which a bad C++ instructor would skip or botch too, right?= ) as the =E2=80=A2=E2=80=A2enlightened way to bring OP's thinking-in-Ada to= novice C++ students=E2=80=A2=E2=80=A2. Of these, only your unspecified al= lusion to Pimpl as an idiomatic work-around for lacking Ada's separately-co= mpiled private portions of packages is higher in the food chain of bringing= think-in-Ada to C++. The others are not bringing think-in-Ada to C++ at a= ll; they are merely garden-variety everyday barebones run-of-the-mill embra= cing of the commonplace party-line mantras in C++. On Sunday, July 1, 2018 at 3:52:37 PM UTC-5, Maciej Sobczak wrote: > Ada is strong in directing the user towards a good program structure. Pic= k this and try to show your > students =E2=80=A2=E2=80=A2how to design the program in C++ using the too= ls that it has=E2=80=A2=E2=80=A2 - =E2=80=A2namespaces=E2=80=A2 and > =E2=80=A2classes=E2=80=A2. The notion of packages in Ada do not map 1:1 i= nto =E2=80=A2namespaces=E2=80=A2 and =E2=80=A2classes=E2=80=A2 in C++, but > the big picture of encapsulation and program decomposition translates wel= l. Show them how the > physical structure of translation units in C++ can be used to enhance enc= apsulation [e.g., the PIMPL > idiom]. Show them how to use =E2=80=A2templates=E2=80=A2. Use the =E2=80= =A2standard library=E2=80=A2 whenever you can. Then in that paragraph, you switch to the negative, telling OP what not to = do, but never positively telling the OP what to actually teach in Ada-think= regarding C++'s utilization of or avoidance of pointers, lvalue references= , rvalue references, ::std::unique_ptr, ::std::shared_ptr, and/or ::std::we= ak_ptr. (Indeed, are only pointers =E2=80=9Craw pointers=E2=80=9D in your = negative scorched earth or are all the others on the list too to be avoided= ? and where? and how?) The OP is yearning for: what portion of accesses a= nd pools and subpools can be brought over from Ada's wise memory management= (and the incrementally-formulating-a-proof-by-mathematical-induction rules= thereof)? and how? > Stay away from raw pointers as long as you can (which might as well be fo= rever). Then the next paragraph is hardly anything other than negatively casting as= persions on Luke & my advice to bring over more sophisticated specific thin= king-in-Ada concepts, and what it would take to raise C++ up a bit, a littl= e closer to Ada's level of software-engineering wisdom. That next paragrap= h is repeatedly telling OP what /not/ to do, instead of advising which thin= k-in-Ada concepts can be brought over to woo C++ programmers to Ada-think= =E2=80=94if not woo over to Ada the language, woo over to the standing-on-t= he-sholders-of-giants-who-came-before software-engineering wisdoms througho= ut Ada. Negativity and embrace-the-pure-tried-&-true-party-line-C++-way wa= s not what OP was requesting. > Now, I take the risk of being controversial here, but I have enough C++ e= xperience to stand by my words: > don't bother implementing your own broken version of integer ranges in C+= +, no matter whether with > macros or with templates. Just don't. Overtly declaring the range of integers over which this portion of code ope= rates can be a key portion of eliminating all variants of the overflow/over= run vuln(erabilitie)s that worms utilize as their attack vector to insert m= achine code. But never mind SEI software engineering principles, eh? Obey= the party-line mantra of C++ without deviation, eh? Don't try to evangeli= ze think-in-Ada to a nonAda audience, eh? Keep all that Ada stuff behind y= our Ada community's closed doors, eh? Btw, integer ranges were merely utilized in passing by me as an easy-to-see= -at-a-glance example in crawl, walk, run warm-up to meatier topics to bring= over from Ada: 1) pool-based memory management, emulating Janus Ada-esque sharing of singl= e copies of generic/template instantiations to avoid bloat, 2) rendezvous idiom for multithreading, 3) C++'s Pimpl idiom to emulate Ada's separate compilation of private porti= on of packages, 4) emulation of discriminated records, 5) enum class as emulating Ada's strongly-type enumerations, and so forth, each of which are too big for newsgroup postings. > If you try to do this, you will teach your students something that > they will not be able to reuse or translate in the real world, in the rea= l existing code. Why not? Is the professor's teaching copyrighted and licensed only under a= restrictive license? Why can't his students go forth and prosper as evang= elists of a better way? Why must C++ be practiced as only, say, the Boost'= s mailing-list prescribes? Why should the The One True And Only Way cult b= e the only C++ culture permitted? Why should thinking-in-Ada/thinking-in-S= EI-software-engineering be a code smell in C++? > You will be blamed afterwards for the bad teaching C++ community runs a black list to ostracize heretics disbelieving in The O= ne True And Only Way cult, eh? Wow, who knew? > and you will have nothing to defend yourself. Yeah right, nothing other than an ever-bigger-every-year group of well-trai= ned students who evangelize the better way in code reviews and the mental b= attle that is corporate or open-source software development. Which, btw, i= s the only defense a professor ever has over the years in the end: whose l= ives did the teaching transform toward the better? > Just don't. It is true that some attempts have been made in this directio= n, Yeah like the following yet another major contribution of think-in-Ada deep= -wisdom worthy of taking to C++, eh?: > #define begin {=20 > #define end }=20 If begin-end instead of {} is some of the think-in-Ada deep-wisdom with whi= ch to enlighten C++ students with Ada's better way, then perhaps I have dra= stically overestimated how much Ada's deep-wisdom has disseminated out from= the luminaries/_LRM_/_AARM_/_Rationale_s to the tens of thousands of Ada p= rogrammers. Ada wisdom has so much more software-engineering wisdom to tea= ch C++ students than mere surface-level syntax. > but none got any recognizable acceptance. C++ is not the language for doi= ng ranges I suppose C++ is not the language for doing interval arithmetic over the re= al-numbers-with-tolerances either, eh? I suppose C++ classes cannot repres= ent scalar data types well at all, eh? I suppose that the people who build= out such libraries (even for inclusion into the C++ standard library) are = fools (and should be put on that aforementioned black list =E2=80=9Cwith no= thing to defend [themselves]=E2=80=9D for practicing C++ without the proper= license from The One True And Only Way cult), eh? Here are some libraries= for interval-arithmetic over real numbers in C++, utilizing C++ classes (g= asp!) for =E2=80=9Cmicromanaging=E2=80=9D each number: https://docs.oracle.com/cd/E19422-01/819-3696/iapgCreference.html http://www-sop.inria.fr/members/Sylvain.Pion/cxx/interval/interval.pdf > and I'm not sure whether this is entirely bad - don't confuse them with r= ange-checked arrays, Yeah right, the upper and lower bounds of an integer constrainment range is= strictly forbidden to be utilized when calculating the number of elements = in, say, a ::std::vector or ::std::array, eh? Magic-number numeric-literal= s are best, eh? Constants out of left field are almost as good, eh? The e= quivalent of 'First and 'Last on a constrained integer range=E2=80=94no, no= , that is far too much colocation of concepts so that the programmer doesn'= t need to looking hither and yon for some named constant, eh? > which are available in the standard library and are (and should be) used.= In the same spirit, don't get > obsessed too much on defining gazillion of incompatible types for everyth= ing, as some Ada books insist > on. or that C++'s enum class was added for or that strong typedefs are yearned as being (analogous to MyType is new Ty= pe in Ada): https://foonathan.net/blog/2016/10/19/strong-typedefs.html Yeah right, C++ programmers haven't been yearning for Ada's strong typing o= n those =E2=80=9Cgazillion of incompatible types=E2=80=9D, eh? > Classes as separate types are good for medium to big design concepts, and tiny design concepts such as each number or each type alias > but not for micromanaging integers. And not for micromanaging 3 categories of complex numbers in the C++ standa= rd and Boost libraries: complex, quaternions, octonions, eh? https://www.boost.org/doc/libs/1_34_0/doc/html/boost_math/quaternions.html https://www.boost.org/doc/libs/1_34_0/doc/html/boost_math/octonions.html And not micromanaging the aforementioned interval-arithmetic real numbers, = eh? > Don't bother with reimplementing Ada in C++ at this level and you > will be successful in your teaching. Yeah right, teaching students to be evangelists of better ideas is a recipe= for being a bad teacher, eh? Teaching novices to be verbatim-copy drones = of The One True And Only Way cult is the only way to be successful in teach= ing, eh? > You have skipped other important points that I have made. To be fair, I subjected your other points to additional scrutiny this time = around, to dismantle them too.