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,782af4edeb84c4b7 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: basic basic ada question Date: Fri, 20 Oct 2006 16:59:49 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1161268231.345231.242170@m73g2000cwd.googlegroups.com> <4537bc65_1@newsfeed.slurp.net> <5567b72ia0c9$.1b6yl0tpfscj5$.dlg@40tude.net> <13bxqw4vydm93$.vlnod0hnsogo.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1161377996 31357 192.74.137.71 (20 Oct 2006 20:59:56 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 20 Oct 2006 20:59:56 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:y/JYhgGr1RhfCubKtNjWb0gxyfM= Xref: g2news2.google.com comp.lang.ada:7108 Date: 2006-10-20T16:59:49-04:00 List-Id: "Dmitry A. Kazakov" writes: > On Fri, 20 Oct 2006 11:29:35 -0400, Robert A Duff wrote: > >> "Dmitry A. Kazakov" writes: >> >>>...2) a proper construction model, ... >> >> What do you see as the problems with Ada's construction model? > > 1. All kinds of types without exceptions should support user-defined > constructors. I agree. Of course this is already true for constructor functions. If you're talking about default values, then yes, I agree that it's a kludge that records can have defaults (via component defaults) but other types cannot. But now that Ada 2005 allows limited constructor functions, I wouldn't mind eliminating per-type default values altogether. (I mean from a pure language-design point of view -- of course nobody is going to make such an incompatible change to Ada.) I prefer to say: X: Integer_Sequence := Empty; rather than having Integer_Sequence default to an empty sequence. Return-by-reference was a bad mistake in Ada 95. It's very cool that in Ada 2005 you can say: function F(...) return T; where T is limited, contains tasks, etc, and F creates a new object of type T. > 2. The semantics of construction / destruction of the bases should be > enforceable. (Presently only components enforce their construction > semantics). This requirement is applied to abstract bases, interfaces and > interfaces inherited from concrete types (presently not allowed) I don't understand what you mean by the above. It would be nice to have a feature to prevent uninitialized variables. It would be nice to have invariants that constructor functions must obey (similar to Eiffel). But I'm not sure those are what you meant... > 3. Same for copy constructors. Assignment should be defined in terms of > copy constructors. Yes. We tried to do it that way in Ada 95, and failed, because we didn't know how to make it work for types with defaulted discriminants. There's some discussion of this in the AARM. > 4. Dispatch. There should be a safe way to dispatch upon construction / > destruction. As I see it, this is related / equivalent to providing > class-wide constructors. Again, not sure what you mean. We do have class-wide functions. How can dispatching work, when you are creating an object -- dispatching requires a Tag, and that's part of what you're creating. > 5. Determining constraints (and so the object size) from the constructor > parameters. Works fine for constructors-as-functions. You can also use discriminants as "parameters". > 6. All types should support construction per user-defined aggregates. Yes. I strongly agree. Also user-defined literals. >> I think "a function that returns T is a constructor for T" >> is a pretty good idea. I should have said "returns a new object of type T" instead of just "returns T". > A constructor (+ allocator) is a factory, but not every factory is a > constructor. A constructor produces a valid object from raw memory. Any > constructing function should in the end directly or not call to a proper > constructor, which still exist, though maybe is language defined. So to > pretend that there is no one does not help the language. Clearly, when a > task is created there is a lot of things to happen before it becomes valid. > Even for simple types I prefer to think that the constructor is null, > rather than there is no one. I think the above makes sense, although I'm not sure exactly what you mean by "factory" -- to me, a factory is a module that constructs objects, usually based on some parameters passed to it. >> I don't like the "all constructors >> are implicit/anonymous" idea from C++ and others. > > But Ada allows declare X : T; thus it has default constructors. Why then > the user should not be able to override some parts of the constructor? I'm not sure default constructors are really a good idea. When you say "X: T", you don't know (without looking at the private part where T is declared) whether X is a valid object of type T, or just uninitialized junk. If default values are allowed, it seems to me that this distinction should be part of the contract. - Bob