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.8 required=5.0 tests=BAYES_00,PLING_QUERY, WEIRD_PORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,2f6e39a9d25bcd8b 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!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: how to organize source code for a complete software? Thanks! Date: Sun, 09 Oct 2011 20:37:43 +0200 Organization: A noiseless patient Spider Message-ID: <878vouovt4.fsf@ludovic-brenta.org> References: <9fe53iFoe7U1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="gSxNhgQE+HIttW+NYbdggA"; logging-data="9025"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wgPPpHrOE+AXH0JvdhmPV" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:erDxtcE6QV/SGEoqO00h+DT/TqE= sha1:4NFQSzoGabji4txZ9yXoT7AA5Aw= Xref: g2news1.google.com comp.lang.ada:21341 Date: 2011-10-09T20:37:43+02:00 List-Id: Niklas Holsti writes on comp.lang.ada: > On 11-10-09 18:20 , Jinsong Zhao wrote: >> Hi there, >> >> I am new to Ada, and I just have some experiences in using Fortran. > > Welcome, then. May I ask what attracted you to Ada? I am asking partly > out of curiosity, but also because if you tell us what you hope to > gain by using Ada, we may better advise you on how to organize your > code, and on other Ada usage. I am curious, too. >> When using Fortran, I generally put each subroutine or function in a >> separate file, e.g., dot.for for dot product of two vectors. Then a >> main.for that call the necessary subroutine or functions. It seems to >> be rational. OK but where do you place variables that are shared by multiple subroutines or functions? Where do you place type declarations? This is quite crucial for my point below. >> When I using Ada, I don't know how to do. In addition to the rules of thumb given by others, I'll now explain the reasoning behind a proper choice of where to place your subprograms. It's all about _visibility_. package P is -- this part is visible to anyone who says "with P;" private -- this part is visible only from the body of P end P; package body P is -- this part is completely hidden end P; procedure Proc is -- this part is completely hidden begin -- this part is completely hidden end Proc; A subprogram declared in the package P can see everything in the public and private parts of the spec; it can also see everything that has been declared above it inside the body. Thus, a package spec will normally look like: package P is type T is private; procedure Foo (Param : in out T); private type T is ...; end P; If several subprograms use the same type T in their specs, then they should all be declared in the same package. So, my advice to you is to organize your sources not in terms of subprograms, but in terms of types; each major type should be in a package of its own, along with all the subprograms that operate on it. One example that I wrote is here: http://green.ada-france.org:8081/revision/browse/108fe173864fa16185a547d486849a475dd3c2a3 You will find one main subprogram (test.adb), one spec (s_expression.ads) declaring a type T and all subprograms operating on it (the type T is private and its details are in the private part of the spec), and one package body (s_expression.adb) containing the implementation of those subprograms. -- Ludovic Brenta.