comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <nickroberts@callnetuk.com>
Subject: Re: Modular types inside records
Date: Wed, 25 Oct 2000 02:50:07 +0100
Date: 2000-10-25T02:50:07+01:00	[thread overview]
Message-ID: <8t5gs7$m1sl5$2@ID-25716.news.cis.dfn.de> (raw)
In-Reply-To: 8FD6C49EFPablo@213.25.200.9

Totally off-base, Pawel!

One of the things you must learn, if you are going to become a professional
Ada programmer, is what is grandly called 'decoupling'. This means, in
essence, making the interfaces between modules as simple as reasonably
possible. In the case of bottom-up programming (which includes your
example), this generally means making the interface as simple as
(reasonably) possible for 'users' of your package.

Does adding the 'mod_n_max' generic parameter make things easier for users
of your package? It surely does not.

Trust me, something like:

   if Front = Buffer'Last then
      Front := Buffer'First;
   else
      Front := Buffer_Index'Succ(Front);
   end if;

is a terrifically simple piece of code, as code goes. In your time, you will
come across multi-KSLOC Gorgons that will make you have to change your
underpants. You will come to eat the kind of fragmentette above in one gulp.

Oh harken ye to the words of the old and grizzled: it's not the car that has
the fanciest gadgets that wins the race, it's the one that manages to
actually finish the race.

Another way to think of it is like this: programming is not an art, it's
just a way of getting a job done. And, believe me, this comes from a man who
deeply believes that programming is an art.

Or, another way is this: you have to know a lot in order to know a little.

Okay, so how do we 'pros' do it, then? By declaring a 'Cyclic_Succ' function
of course:

generic
   type Element_Type is (<>);
function Cyclic_Succ (Item: in Element_Type) return Element_Type;

Neat huh? I'll leave the implementation and use of this function to you.

All the best,

--
Nick Roberts
http://www.AdaOS.org

PS: If you need to remove Constraint_Error checks, for speed, you can use
pragma Suppress (after testing).






  parent reply	other threads:[~2000-10-25  1:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-10-21  0:00 Modular types inside records Pawe� Niewiadomski
2000-10-21  0:00 ` Robert Dewar
2000-10-21  0:00   ` Pawe� Niewiadomski
2000-10-21  0:00     ` Jeff Carter
2000-10-21  0:00       ` Pawe� Niewiadomski
2000-10-23  0:00     ` Robert A Duff
2000-10-23  0:00       ` Pawe� Niewiadomski
2000-10-24  0:00         ` Robert A Duff
2000-10-25  1:50         ` Nick Roberts [this message]
2000-10-25  0:00           ` Pawe� Niewiadomski
2000-10-27 22:05         ` Robert Dewar
replies disabled

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