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!feeder.news-service.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool4.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> <18wh86jvjvoe0.cofxcc8udm6q$.dlg@40tude.net> <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> Date: Tue, 1 Dec 2009 17:18:30 +0100 Message-ID: <19nhib6rmun1x$.13vgcbhlh0og9$.dlg@40tude.net> NNTP-Posting-Date: 01 Dec 2009 17:18:30 CET NNTP-Posting-Host: 1fc09bf7.newsspool1.arcor-online.net X-Trace: DXC=AAYH2;P5S1XHigV@eW57PQic==]BZ:af^4Fo<]lROoRQ<`=YMgDjhgRi>i_0d9ba9VR2A^ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8270 Date: 2009-12-01T17:18:30+01:00 List-Id: 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. (Provided, we are talking about a typed language) >> ------------------------- >> Anyway, you cannot do that because: >> >> if HALT (P) then >> X := Z; >> end if; >> Y := X; -- Is this legal? > > (HALT is a run-time issue that has no impact here.) If you cannot decide if X is "initialized", then you cannot decode whether the program is legal. However you could define some set of pragmatic rules with either many false positives or many false negatives, or even mixed. These rules will be most likely observed as arbitrary by laymen. I don't think the issue deserves this. > While this snippet would not be legal as is (on purpose!), > Ada's case coverage rules can make the programmer write a > legal program easily: write an else branch! And this one: procedure Foo (X : in out Car); ... begin Foo (X); Y := X; -- Is this legal? Probably, already the call to Foo is illegal? And if Foo were declared as procedure Foo (X : out Car); >>> 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. Java does not have constrained types, so I can understand why they go this way. I think it is better to ensure that a declared value is initialized at the declaration point. 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. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de