Programming best practice

The following are a few points about programming best practice. Following these steps will help you create much better software.

Ada is an incredible too that allows you, with minimal effort, to create software that works. Although your algorithm may suck (in which case you'll have to fix it) the rest will just work or break quickly. In other words, a legal Ada program is likely a fully functional program.

The Perfect Program

Obviously the best would be to program without errors from scratch. This would be neat. It's not going to happen too often, I'm afraid... The following are the main


Gnat and pragma pack() big surprise

Today I worked on a set of tables used to determine the category of all the Unicode characters as supported by Ada 2005. First I attempted to create that in software using two levels of case, but it quickly became obvious that it would be large and probably inefficient. The result was about 152Kb of nearly only code.

After some thought, it seemed that if I were to create full tables of 256 x 3 bits (768 bits or 96 bytes) as the category can be compressed in that way, then it would generate tables 94 tables of 96 bytes = 9,024 bytes (~8.8Kb). Really cool. So I decided to create a packed


In and In Out parameters on a function call

If you've been programming for a while, you ran into variables passed by reference. This means the callee will be able to change the content of the caller's variables.

In general, such a call looks something like this:


Assuming that this_proc() variable parameter is defined with in or in out, this means this_proc() can do my_var := <expression>; and that <expression> is what will be in my_var when the procedure returns.

However, in Ada, there is a subtle difference. The fact is that my_var is likely going to


Ada Exponentiation surprises

Among all the languages I know, Ada is one of the few that offers and exponential operator: **.

In mathematics, you generally write an exponential using a small font and moving the exponent up above the normal line. The notation of x power y is written this way:

xy               (1)

I will assume that most people know that a negative number power an odd number is negative. The same negative number power an even number is positive. So for instance, -1 power 3 is -1 and -1 power 2 is 1:

-13 = -1    ...