From: stefan-lucks@see-the.signature
Subject: Re: how to organize source code for a complete software? Thanks!
Date: Sun, 9 Oct 2011 19:16:33 +0200
Date: 2011-10-09T19:16:33+02:00 [thread overview]
Message-ID: <Pine.LNX.4.64.1110091853450.19815@medsec1.medien.uni-weimar.de> (raw)
In-Reply-To: <j6shle$h5f$1@dont-email.me>
> 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.
> 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>
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.
--
------ Stefan Lucks -- Bauhaus-University Weimar -- Germany ------
Stefan dot Lucks at uni minus weimar dot de
------ I love the taste of Cryptanalysis in the morning! ------
next prev parent reply other threads:[~2011-10-09 17:16 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 [this message]
2011-10-10 5:52 ` Jinsong Zhao
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