Tag Archives: ada

Type safety

Consider the method findByDate that executes a query to find something by the year and month. One way of implementing this method in Java can be with two parameters year & month, both of type int. But this has some problems with passing valid arguments to methods and statically type checking.

public function findByDate(int year, int month) {
  // do stuff
}

Continue reading Type safety

Ada: A strict language

A first encounter with Ada takes Adame back with programming a few years because there are a lot new or slightly different concepts compared to Java or PHP. So simply creating a program and trying to run will often end in an error from the compiler. Understanding why these error occur are key in understanding the design of Ada and why it is so strict in a lot of ways. The first two problems I encountered when starting with Ada are the following. Continue reading Ada: A strict language

Ada: Hello world

Learning a new language always start with the famous words “Hello world”. This article will show how creating a “hello world” application is done in Ada.

First you should make sure the free Ada compiler is installed, check if the command gnatmake is available. When it is not you should install it with apt-get install gnats on Linux. This compiler is provided as open source by the GNAT Pro company that also provide the Pro version for mission critical support.
Start with a file and name it test.adb, .adb is the default Ada file suffix.

with Ada.Text_IO;
use Ada.Text_IO;

procedure test is
begin
   Put_Line("Hello world");
end test;

Now compile the file to an executable with the command gnatmake:

$ gnatmake test.adb
gcc-4.6 -c test.adb
gnatbind -x test.ali
gnatlink test.ali

The executable file test should be compiled and in the current directory. To try the program execute this file with ./test.

$ ./test
Hello world

So that’s it! A real simple but working program in Ada. Below is a short description about the different lines of code and what they do and mean:

  • Row 1 and 2, In Ada you should define which packages you want to compile within the executable and which package you want to use within the scope. The use Ada.Text_IO could be ommitted but then row 6 should be prefixed with Ada.Text_IO to make clear from which package the Put_Line is coming.
  • Row 4,5 and 7, We define the procedure test and include a begin/end block. A procedure can be compared with a function but does not return any value. A procedure does more but that will be covered in another article.
  • Row 6, Put_Line outputs the string to the console. This procedure is defined in the package Ada.Text_IO.