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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,dbbbb21ed7f581b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Operation can be dispatching in only one type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <025105f2-5571-400e-a66f-ef1c3dc9ef32@g27g2000yqn.googlegroups.com> <53a35ed9-88ac-43dc-b2a2-8d6880802328@j19g2000yqk.googlegroups.com> <4b091fb9$0$6567$9b4e6d93@newsspool4.arcor-online.net> <1w0q3zxzw79pt$.5z0juiky7kfd$.dlg@40tude.net> <0f177771-381e-493b-92bb-28419dfbe4e6@k19g2000yqc.googlegroups.com> <1nbcfi99y0fkg.1h5ox2lj73okx$.dlg@40tude.net> <59acf311-3a4a-4eda-95a3-22272842305e@m16g2000yqc.googlegroups.com> <4b150869$0$6732$9b4e6d93@newsspool2.arcor-online.net> <18vlg095bomhd.8bp1o9yysctg$.dlg@40tude.net> <4b152ffe$0$7615$9b4e6d93@newsspool1.arcor-online.net> <19nhib6rmun1x$.13vgcbhlh0og9$.dlg@40tude.net> <4b1557d0$0$7623$9b4e6d93@newsspool1.arcor-online.net> Date: Tue, 1 Dec 2009 19:47:08 +0100 Message-ID: NNTP-Posting-Date: 01 Dec 2009 19:47:06 CET NNTP-Posting-Host: a00be597.newsspool3.arcor-online.net X-Trace: DXC=\=AFd9V^V1_Fm0Y?OE@2^XMcF=Q^Z^V3X4Fo<]lROoRQ8kF>g5^TeGOF^_:ZUL37^BU\ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8274 Date: 2009-12-01T19:47:06+01:00 List-Id: On Tue, 01 Dec 2009 18:52:15 +0100, Georg Bauhaus wrote: > Dmitry A. Kazakov schrieb: >> On Tue, 01 Dec 2009 16:02:21 +0100, Georg Bauhaus wrote: >> >>> Dmitry A. Kazakov schrieb: >>>> On Tue, 01 Dec 2009 13:13:29 +0100, Georg Bauhaus wrote: >>>> >>>>> Then we could rely on the language: compilers will detect >>>>> uninitialized variables provided these do not have a pragma/keyword/... >>>>> to say that uninitialized is what the programmer wants. >>>>> Some fancy means to tell the compiler that this variable >>>>> does indeed have a good first value like pragma Import. >>>>> >>>>> X : [constant] Car; -- default init, >>>> The error is here! >>>>> -- undefined, >>>>> -- junk bits. Doesn't matter >>>>> -- *no* pragma Import (Ada, X); >>>>> >>>>> begin >>>>> >>>>> Spare := X.Tire (5); -- would become illegal, >>>> Not here! >>> Why? >> >> Because X is illegal right after begin: >> >> IF accessing X is illegal THEN the corresponding operation does not belong >> to the type of X THEN the type of X is not Car. q.e.d. > > But the implications of this proof are purely formal, > and not relevant before X is used. They are relevant to the declaration of X. It cannot be declared of Car, if it is not. > There is no way to perform an operation involving X in > its own declaration. But it can be used right after the declaration. > The difference in views would be that your laws say Don't > create objects that could be used illegally if there > were uses that can't be there, though, but for formal reasons. > Whereas Java's ruling says (at compile time) Your program > cannot be accepted because this object cannot be in > a legal state here. No, Java says, that it self failed to prove that this object is in a state the programmer might want. This is an absolutely informal statement, because Java cannot have any idea about what the programmer actually wanted. The only basis for reasoning might be the object type. But that tells nothing. So Java speculates that the default constructor is somewhat worse than copy constructor. Why does it so? Did programmer told this the compiler? No he didn't. Yes, it might be the case, but then why not to allow the programmer to say exactly this: do not allow default constructors for this type? I would even make this a default. E.g. if the programmer does not explicitly allow default constructors they are forbidden. So X : T; -- Is always illegal unless I do some actions >> (Provided, we are talking about a typed language) > > I think there is more in what you say than what is covered > by the words "typed language"? properly typed language! (:-)) >> And this one: >> >> procedure Foo (X : in out Car); >> ... >> begin >> Foo (X); >> Y := X; -- Is this legal? > > Yes, this is legal, because Foo is called with X having been > assigned a value. But Foo might read X in its body before updating it. It can leave it untouched etc. >> And if Foo were declared as >> >> procedure Foo (X : out Car); > > We'd have roughly the same as this: > > X : Car; > begin > X := Foo_as_function; -- now X can be used > > I see no operational problem. Is there one? There is one, Foo might leave X unchanged, unless you introduce further special rules for out parameters. It will be interesting: begin begin Foo (X); exception when Baz => null; end; Y := X; -- Is this legal? Ada does not specify what happens with out parameters updated before an exception gets raised in the body of Foo: procedure Foo (X : out Car) is begin if HALT (p) then raise Baz; -- Is this legal? else X := Merzedes; end if; end Foo; >>>>> Does the phrase "first value" make sense? >>>> An object shall not have invalid values. All values are valid if the >>>> language is typed. Enforcing user-defined construction including >>>> prohibition of certain kinds of construction (e.g. per default constructor) >>>> is a different story. >>> If you feed this to a Java compiler you will see how it is done. >>> The Java compiler will not accept a reference to a variable's >>> component when the variable may not have been initialized. >> >> I consider this model wrong. It is better not to introduce inappropriate >> values rather than trying to catch them later. > > The Java rule works at compile time. No value is introduced at any > time during compilation. Nothing to catch. Of course there is something to catch. The compiler has to do this. So the question is at which cost, how many false positives and negatives it will find? How scalable is this feature for more elaborated types? >> Java does not have >> constrained types, so I can understand why they go this way. > > Ehm, I don't see the connection here. Which one is it? > > When I declare > > X : Some_Type(Some_Constraint); > begin > -- X may need further "initilization", and assigments, since > -- Some_Type is an "open minded" type of a varying nature, > -- not a fixed value. Its objects accumulate values. I mean constraints in a wider sense. For example: Some_Time (<>) e.g. a subtype that would require explicit initialization. >> I also think that forward uninitialized declarations represent bad >> style, e.g.: >> >> function Foo (...) return Bar is >> Result : Bar; >> begin >> ... >> if ... then >> raise Baz; >> end if; >> ... >> Result := ...; >> ... >> return Result; >> end Foo; >> >> I understand the motivation to declare Result uninitialized (because we >> could leave Foo via an exception), but I don't like this. > > But assigning the first value when declaring X won't help > when the initialization can raise exceptions. How could this change? I don't follow you. My example illustrated a situation where an uninitialized value might be an advantage, because one possible outcome of Foo is exception propagation, in which case leaving Result raw could save some vital nanoseconds of execution time. I don't buy this. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de