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,999932ecc319322a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-feed01.roc.ny.frontiernet.net!nntp.frontiernet.net!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: advice on package design Date: 17 Mar 2005 16:26:22 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1110212638.336123.298580@l41g2000cwc.googlegroups.com> <1gbk0qx2sgzpg$.sltzfssofla8$.dlg@40tude.net> <3jok3ghqqls8$.1rrsonb8jsurt$.dlg@40tude.net> <88zllqj1min5$.fqqxis9i327d$.dlg@40tude.net> <18e9a92kz25wu$.8b965bel5vef$.dlg@40tude.net> <1dgodaruwhhwo$.1baazg490isjx.dlg@40tude.net> NNTP-Posting-Host: shell01-e.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1111094783 14531 69.38.147.31 (17 Mar 2005 21:26:23 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 17 Mar 2005 21:26:23 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:9566 Date: 2005-03-17T16:26:22-05:00 List-Id: "Dmitry A. Kazakov" writes: > I like the separation very much. You're not alone. Part of my reason is that declarations in Ada execute code at run time. In other languages (e.g. Pascal) there is a strict separation: declarations declare, statements execute, so it makes sense to have a syntactic line drawn between the two. But in Ada, the decls can do real work, so the line drawn by the "begin" is misleading. In some cases, the decls do *all* the work, especially when you're working with Strings, where the length usually depends on the initial value. Then the procedure body says "null;", meaning "this does nothing", which is a lie. Sometimes you end up with long chains of deeply nested declare blocks: function F(...) return String is A: String := ...; begin Do_Something(A); declare B: constant String := G(A); begin ... and so on .................................. declare Z: String ... begin return Z; Yuck. Another thing that I trip over once in a while is I want a *statement* near the beginning of a package body. It is important that it execute at the point, because following code (yes, decls are code!) depends on it. You can say this: package body P is package Defeat_Annoying_Syntax_Rules is end; package body Defeat_Annoying_Syntax_Rules is begin Initialize_Database; end; ... -- 200 lines of code end P; But that seems less readable (to me) than just writing "Initialize_Database;" where I want it to happen. So a rule (requiring "declare") that is intended to increase readability actually decreases it. And if you want a statement in a package *spec* (say, to initialize something), it's far worse. There's no direct workaround; you have to totally rearrange the structure of your design in order to get around a silly syntax rule. It seems to me that: Mumble: T := Blah(...); should be precisely equivalent to: Mumble: T; Mumble := Blah(...); which should be precisely equivalent to: Mumble: T; Blah(Mumble); (where in the last example we replace function Blah with a procedure with an 'out' parameter). The programmer should be able to switch from one of these forms to another, without changing the semantics of the program. But the syntax rules require stirring the code around when you make these changes. (Another reason Ada does not have the above desirable property is that function results of subtype String behave differently from 'out' parameters of subtype String. I don't like that.) > But let's consider getting rid of declarations. Wouldn't it be fake anyway? > You know that better than me, but I suppose the compiler will need to move > everything to the beginning of the closest scope. Otherwise: > > if Halt(x) then > declare A; > end if; > Foo (A); -- Would it be legal? By "declare A;" I assume you mean something like "A: Integer;". No, A would not be visible at the call to Foo -- it would be just like putting a declare block inside the if statement in the current language. I'm not proposing anything different in the semantics, here -- just a minor syntax change. > T := (1, 2, 4, declare X := 9, others => declare Y := 10); > -- What would be this? How many Y's could be here? No, I don't propose to allow mixing of decls and expressions! Just decls and statements. Decls don't return values. > So I see no advantage in this. Convinced? Partly convinced? ;-) - Bob