comp.lang.ada
 help / color / mirror / Atom feed
From: Jinsong Zhao <jszhao@yeah.net>
Subject: Re: how to organize source code for a complete software? Thanks!
Date: Mon, 10 Oct 2011 13:52:38 +0800
Date: 2011-10-10T13:52:38+08:00	[thread overview]
Message-ID: <j6u178$hgj$1@dont-email.me> (raw)
In-Reply-To: <Pine.LNX.4.64.1110091853450.19815@medsec1.medien.uni-weimar.de>

On 2011-10-10 1:16, stefan-lucks@see-the.signature wrote:
>> I am new to Ada, and I just have some experiences in using Fortran.
>>
>> 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.
>>
>> When I using Ada, I don't know how to do. There are procedure, function,
>> package, package body, and so on (with different file extension, e.g., ada,
>> adb, ads, ...). And there is no main program.
>
> 1. Any parameterless procedure, which is not "local" inside another
>     function/procedure or inside a package, can be the main program.
>
> 2. As a rule of thumb for beginners: Put your auxiliary subprograms (in
>     Ada: a subprogram is either a function or a procedure) and the requited
>     type definition into packages. Write a single parameterless main
>     procedure as the "main" procedure, but give it a meaningful name
>     ("Solve_Linear_Equations" or "Delete_File" rather than "Main"). Put
>     that procedure into a file of its own.
>
> 2a. Note that a package consists of a specification and an implementation,
>      which are usually put into TWO different files (e.g., "name.ads" for
>      the spec and "name.adb" for the implementation body).
>
> 2b. When you are more advanced in programming in Ada, you may sometimes
>      want to compile "separate" subprograms without wrapping them into
>      packages.
>
> 3. Compile the main procedure (e.g., by calling "gnatmake" if you use the
>     gnat Ada compiler) -- your compiler will know which packages it needs
>     to compile.

Thank you very much. The above statements give me more information than 
what I get from the books available to me here. Now, I think I know how 
to layout my small program.

>
>> And, please, if you like, point me a small, complete open source software in
>> Ada (not a library or package). I should be compiled and run. I just hope to
>> learn how to start a software in Ada by example.
>
> Examples:
>    <http://rosettacode.org/wiki/Linear_congruential_generator#Ada>
>    <http://rosettacode.org/wiki/Ternary_logic#Ada>

It's a nice place for me. Thanks!

>
> The linear congruential example would consist of three files:
>    1. the specification "lcg.ads",
>    2. the implementation "lcg.adb", and
>    3. the main program "run_lcgs.adb".
> (These are the gnat/gcc naming conventions, look into your compiler
> documentation if you use another compiler.)
>
> As an easy exercise for the reader, try to figure out which three files
> the ternary logic example would consist of.
>
>
I think I can get the answer:
1. the specification "logic.ads",
2. the implementation "logic.adb", and
3. the main program "test_tri_logic.adb".

Thanks again for your informative reply and the example codes.

Regards,
Jinsong



  reply	other threads:[~2011-10-10  5:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-09 16:20 how to organize source code for a complete software? Thanks! Jinsong Zhao
2011-10-09 17:16 ` stefan-lucks
2011-10-10  5:52   ` Jinsong Zhao [this message]
2011-10-09 17:37 ` Yannick Duchêne (Hibou57)
2011-10-10  6:02   ` Jinsong Zhao
2011-10-10 13:15     ` Paul Colin Gloster
2011-10-10 15:46       ` Simon Wright
2011-10-10 19:03       ` RasikaSrinivasan@gmail.com
2011-10-10 22:12       ` Randy Brukardt
2011-10-09 17:48 ` Niklas Holsti
2011-10-09 18:37   ` Ludovic Brenta
2011-10-09 21:24     ` J-P. Rosen
2011-10-10 12:09     ` Jinsong Zhao
2011-10-10  6:45   ` Jinsong Zhao
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox