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,ed4a5cc4016f9101 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!138.195.8.3.MISMATCH!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Default value for a record component Date: Mon, 23 Jul 2007 20:27:27 -0500 Organization: Jacob's private Usenet server Message-ID: References: <1185052757.500324.16860@22g2000hsm.googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: jacob-sparre.dk 1185240308 29050 69.95.181.76 (24 Jul 2007 01:25:08 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 24 Jul 2007 01:25:08 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1896 Xref: g2news1.google.com comp.lang.ada:16577 Date: 2007-07-23T20:27:27-05:00 List-Id: "Maciej Sobczak" wrote in message news:1185052757.500324.16860@22g2000hsm.googlegroups.com... ... > without losing any of the properties of the original solution and > without "leaking" any implementation detail to the public view. The > idea is, of course, to compute the default value at run-time, each > time the new object is created - but without touching the general > "look&feel" of the original code (so that for example Controlled is > excluded). This is a rather stupid question, especially given the C++ example that you give later. The closest analog to a C++ class in Ada is a controlled type. If you want something like a C++ class, then you are likely to need to use the tools provided in Ada to get that result. Your question is very much like asking how to tighten a bolt that holds together a TV cabinet, but insisting that you will only use a hammer to do so. When someone says "use a wrench" (controlled type), you say "no, I want to use a hammer!" (untagged record type). When someone else says "use a screwdriver" (private part), you say "no, I want to use a hammer!". But a hammer won't solve your problem (unless perhaps you hit yourself in the head with it a few times! ;-) Hinestly, I don't see any sane reason for being unwilling to use a controlled type here. Virtually all new composite types in Ada ought to be controlled types, because there is always some reason that you will (now or in the future) need to have a complex initializer or finalizer. And it's harder to retrofit that later than right away. Moreover, the only real difference for controlled in this example is the syntax used to declare the type; the relevant semantics is essentially identical (how the component is accessed, objects are created, etc.) Which means that your only real complaint is that you don't like "controlled" in the declaration; which is about as silly as saying that Ada doesn't support OOP because it doesn't have a "class" type. In any case, having a type that is visible rather than a private type is almost always a mistake. Yes, Ada allows it, but that's mainly because methodological restrictions don't belong in a programming language (we've dropped many of the ones originally present in Ada 83 because they get in the way in rare but useful cases). And once you allow *anything* to leak about the implementation of a type, there is no real value in hiding any of it -- so Ada doesn't really try to provide such possibilities. Randy.