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: Matthew Heaney Subject: Re: Software landmines (was: Why C++ is successful) Date: 1998/08/28 Message-ID: #1/1 X-Deja-AN: 385474277 Sender: matt@mheaney.ni.net References: <6rnhhe$e2u$1@nnrp1.dejanews.com> <6rsg0d$pcj@dfw-ixnews3.ix.netcom.com> NNTP-Posting-Date: Thu, 27 Aug 1998 18:11:58 PDT Newsgroups: comp.lang.ada Date: 1998-08-28T00:00:00+00:00 List-Id: Richard D Riehle writes: > >... most programmers furiously overuse assignments, and it is > >far too common to see a variable assignment used to establish a constant > >value > > I am not sure what you mean. If I want to define constants, > > Zero : constant := 0; > Null_List := some-value; > > how do I set the initial value without assignment. For private > members in C++ this is really easy without assignment. I can use > (must use) an initialization list. In Ada we have to have an > assignment somewhere to make this happen. The issue lies in the difference between "assignment" and "binding." 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. In the example above, Zero : constant := 0; is a binding operation, not an assignment operation. The name Zero is bound to a value. 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? 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; which is the equivalent of Zero : constant Integer := 0; in Ada. So when Robert says "programmers misuse assignment," he means (I think) that they are using assignment when they really want to use binding. The latter use is indicating by the presence of the keyword "constant". Unfortunately, the syntax for binding in Ada also uses the assignment operator, so Ada programmers blur the distinction between binding and assignment (if they are aware of it at all). I regard this as a flaw in the language.