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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public From: Richard D Riehle Subject: Re: Software landmines (was: Why C++ is successful) Date: 1998/08/28 Message-ID: <6s6v4i$mht@dfw-ixnews8.ix.netcom.com>#1/1 X-Deja-AN: 385719430 References: <6rnhhe$e2u$1@nnrp1.dejanews.com> <6rsg0d$pcj@dfw-ixnews3.ix.netcom.com> Organization: ICGNetcom X-NETCOM-Date: Fri Aug 28 2:06:58 PM CDT 1998 Newsgroups: comp.lang.ada Date: 1998-08-28T14:06:58-05:00 List-Id: In article , Matthew Heaney wrote: In response to Richard Riehle's question about initialization of values with the assignment statement, > >The issue lies in the difference between "assignment" and "binding." I ran to my bookshelf to find an entry in any computer science text on "binding" in the context you have used it. None. Reference, please. >The problem with Ada is that the syntax for both is the same, so >whenever people see ":=" they always think of assignment, even when it >really means binding. I understand the distinction, and your reference to Eiffel, below, is correct. >In the example above, > Zero : constant := 0; >is a binding operation, not an assignment operation. The name Zero is >bound to a value. So, in this respect, C++ initialization lists better express the "binding" requirement than Ada assignments. >Indeed, any time you see the keyword "constant" in a declaration, then >you should treat that to mean "bind," not "assign." >Ada is wildly inconsistent wrt binding. To bind a name to a function, I >use the keyword "is": > >function F (X : T1) return T2 is >begin > >end F; > >means the same thing as > >type FT is function (X : T1) return T2; > >F : constant FT := begin end; > >Why not use the operator "is" everywhere binding is intended? Your function example is interesting. In an Eiffel feature declaration, the syntatical placement for "is" in declaring a function is the same as Ada rather than as you prefer. >I think it's true that in Eiffel, binding doesn't use the assignment >operator, it uses the keyword "is", as in > > Zero : Integer is 0; > This is true. A feature declaration in Eiffel is the same for any declaration. This is called by Bertrand, "the principle of minimum surprise." When referencing any feature in an Eiffel class, the client of the class sees attributes identically to functions. An "is" is used only for constant or routine feature. Non-constant attributes are not initialized with a "is" keyword. Also, the Eiffel model for "attachment" and "reattachment" more closely approximates what you and Robert are describing as alternatives to excessive use of the assignment statement. With that understanding in place, I suggest that, in using the assignment operation for defining constants, the difference between "binding" and "assignment" is a rather subtle semantic issue for most practical programmers. Also, several consecutive assignment statements in Ada will often be more readable than the parentheticaly clauses of function returns that serve as their substitute. Ada, unlike Eiffel, is not designed to reduce the number of assignment statements. The suggestion that we use fewer assignment statements is liable to create the same mess that "gotoless" programming fomented in the COBOL world. Robert knows that pre-ANSI 85 COBOL was inadequately designed to support programs without GO TO statements. Only with the advent of "END ..." constructs did COBOL become more amenable to reducing the number of GO TO's. Ada is designed to encourage the use of the assigment statement. Suggesting that we do not use it so often is probably counterproductive and can only be realized with some important changes in the language. You have already noted some of these, Matthew. Richard Riehle richard@adaworks.com http://www.adaworks.com