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,901038687c38f61c X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Idiom for a class and an object in Ada Date: Thu, 21 Oct 2004 16:11:57 +0200 Message-ID: <4dhfe3d87kxr$.1hmxrp8e7rf2y.dlg@40tude.net> References: <1dljnq136n1j1.2oxluar9ofho.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de hVtzIvD6xfVUeNNUwe3myQOF64zfMVN+wAya5ECJoup6vF1AY= User-Agent: 40tude_Dialog/2.0.12.1 Xref: g2news1.google.com comp.lang.ada:5583 Date: 2004-10-21T16:11:57+02:00 List-Id: On Thu, 21 Oct 2004 12:45:09 GMT, Matthew Heaney wrote: > "Dmitry A. Kazakov" writes: > >> On Thu, 21 Oct 2004 01:46:39 GMT, Matthew Heaney wrote: >> >>> I don't understand this comment. How else do you dynamically create >>> instances of T? >> >> Why should they be created dynamically (heap)? Heap vs. stack is a >> matter of object's scope. It should have little or no impact on the >> design of the type. If it has then probably because of language >> deficiency, as in C++, or, yes, in Ada where there was no way to >> initialize limited objects. That will be corrected soon, I hope. > > My point was that there is *no* difference between Ada95 and C++ here. > My reasons for writing the code as I did (that is, writing a factory > function that returns a pointer) had nothing to do with language. I see it different: 1. Why there should be a factory function? 2. Why that should return a pointer? The reasons for 1 could be: 1.a. There are construction parameters [not the case] 1.b. The result is polymorphic [not the case] 1.c. The language does not provide default object construction [not the case] 1.d. Renaming/aliasing, abstracting from variables [might be, but what's the gain?] The reasons for 2 could be: 2.a. The scope of the objects is dynamic and "new" does not fit [not the case] 2.b. The language has problems with construction on the stack. [might well be, if objects are limited] If we consider all that we will see that it is rather a language problem, that forces us to use pointers. >> For Marin's case the objects are not dynamic. So if read-only objects >> would suffice, one can just use functions returning limited objects: > > Finally, someone else sees the light... But if that is the case, then constants would do the trick. You need no function for that. Initialization is an independent issue. Function returning object is *not* a constructor, it could simulate one, but what for if the language supports construction? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de