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: fac41,2c6139ce13be9980 X-Google-Attributes: gidfac41,public X-Google-Thread: f43e6,2c6139ce13be9980 X-Google-Attributes: gidf43e6,public X-Google-Thread: 1108a1,2c6139ce13be9980 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,3d3f20d31be1c33a X-Google-Attributes: gid103376,public From: Frederic Guerin Subject: Re: Interface/Implementation (was Re: Design by Contract) Date: 1997/09/16 Message-ID: <341F4E9C.785C@sympatico.ca>#1/1 X-Deja-AN: 273108077 References: <340C85CE.6F42@link.com> X-Complaints-To: usenet@news1symp.sympatico.ca X-Trace: news1symp.sympatico.ca 874455689 4515 (None) 206.172.229.156 Organization: cybectec Newsgroups: comp.object,comp.software-eng,comp.lang.ada,comp.lang.eiffel Date: 1997-09-16T00:00:00+00:00 List-Id: Robert Dewar wrote: [ discussing about the possibility of declaring variables after using them ... ] > > int A; > ... > begin > int B := A * 2; > ... > > You will almost always just assume that the A is a backward reference to > the declaration that preceded this. In the rare case where in fact there > is another A ahead of you, you will risk making a significant mistake in > understanding. For sure this would be very difficult to track down. I don't know Algol 68 but I suppose it won't allow you to refer to a forwardly declared variable inside a C++ like block of sequentially executable code. Most likely it will not permit to redefine the same name at the same level as well. So the only case left is something like this ( using Pascal-like ): var A : integer; procedure f(); procedure g(); begin DoSomethingWith(A); (* conterintuitive reference to forward A *) end; var A : integer; begin ... end; ... The question is : Even if the language permit such a thing, will programmers really kill themselves often enough with the added liberty/flexibility ?? > Linear comprehension is a very important capability. All text books have > indexes, which are of course functionally similar to hypretext links, but > we do not say "never mind about presenting things in a logical order, > building on what you have already presented, if you reference something > ahead, people can just look it up in the index". Instead we expend a lot > of effort to present things in a linear order (and indeed software for > computing partial orderings of topics to create appropriate linear orderings > is a standard part of the toolset for educators). > Robert Dewar > Ada Core Technologies There are many *logical* possible orders in which to declare actors ( actor stands for function/variable/constant/etc. ) (1) Sequential: actor must be declared before beeing used. This is what you advocate and it has many advantages. Among which the pitfall previously revealed may not appear. Another involve unexpected recursivity, which may even be worst. But sometimes it is just not the optimal intuitive way to present things. This way to present things is almost necessarily bottom-up, starting with details and reaching the general functions at the end of the sequence. Many people prefer to understand things from the general to the details. Thus this other possible order. (2) Sequential reversed: actor are defined after beeing used. But if this is enforced, it may be worst. For example, it is relatively easy to avoid the previous wrong-variable-referencing pitfall if variables are alway declared before function and procedure. Thus a sort of mixed paradigm seems to be the most appropriate. (3) Mixed: Actors are grouped according to some logic. For exemple as hinted before variable+constant then procedure+function. Another example, from C++. In classes first public members, then private members. Each group possible subgrouped in constructors/destructors, accessors, operators, core-functions, attributes, etc. Some others simply prefers to put the functions in alphabetical orders to facilitate short ranged search by mean of Page-Up Page-Down. Also, if no tools may help and the huge piece of code is in a book, then alphabetical order is almost a necessity. Back to an as old as the historic world technique :-). Just some thinking of mine, Frederic Guerin