EiED Online>> ADA 2005

Dec. 11, 2005
The Ada programming language has been around for years, but its use has typically been restricted to military and space applications. Bill takes a look at AdaCore’s support of the new Ada 2005 standard. See why Ada is worth a look for general embedded app

Although C came about roughly the same time as Ada, C compilers were inexpensive and readily available. C went on to become the defacto standard for embedded development, while Ada kept to its target market, high-reliability military and space applications.

It has been awhile since I used an Ada compiler, and there have been significant changes with the recent Ada 2005 standard. I have also noticed that a number of trends related to safety and reliability are coming from companies that sell Ada compilers. Likewise, Ada has many of the features that make creating solid applications possible and these features are being folded into standards for popular languages like Java and C++.

There are a number of Ada compilers available, including commercial development systems from companies such as AdaCore, Aonix (see “Ada Takes On The Penguin,” ED Online 11351), Artisan Software, Green Hills Software, IBM, and Polyspace Technologies. There are even a number of open-source Ada compilers including the GNU Ada 95 compiler. Later in this article I take a look at AdaCore’s offering that supports the new Ada 2005 standard.

Why Use Ada? Want to write a defect-free program? It will probably be easier to do so using Ada than most other languages. For example, Ada function parameters can have explicit In, Out, or In Out specifiers so there is no guessing what a parameter is used for. Ada also has a very sophisticated type of definition system. All this leads to a complex language, but not when compared to a runtime environment for C++ or Java. In fact, considering the complexity of these other alternatives with all their add-on features, Ada is actually simpler.

An offshoot of Ada’s extensive specification is that Ada applications are easier to maintain than many other languages. Overall, Ada can provide a more productive environment in the long run compared to other alternatives.

The original Ada definition has a number of major deficiencies that were addressed in the Ada 95 standard, the most commonly used version to date. For example, the original did not have object oriented programming (OOP) support and there were no standard bindings, just to mention a few. Ada 95’s OOP support was sophisticated, but its syntax was different than that pushed by C++ and Java. This changed with Ada 2005, which supports the more typical object.method (parameters) style syntax.

Ada has one thing that most languages and environments do not—a self-contained deployment environment. Ada applications can run on a conventional operating system or RTOS, but it is similar to Java in that aspects like multitasking are part of the specification. Ada’s task definitions are much more extensive than those found in Java. One important aspect of this approach is that the program, not the run time environment, provides a description of how the application should perform. This makes Ada applications much more portable than something written in C or C++.

Ada has a wordy syntax like PL/I and Pascal. It also uses := for assignment rather than = used in Java and C/C++. Still, picking up Ada after learning Java or C/C++ is not very difficult. Here is a sample Ada program:

------------------------
-- Hello World program
------------------------
with Ada.Text_Io;
use Ada.Text_Io;

procedure Hello is
begin
   Put_Line("Hello World!");
end Hello;

Put_Line may take a bit more in terms of characters compared to C++’s >> streams, but there is little doubt what is going on when reading the code. Even Ada’s module usage is comparable to systems like Java.

Efficiency is not an issue with Ada at this point. Ada compilers can generate very good code and it supports features like nested function and subroutine definitions that most Java and C/C++ programmers would find unfamiliar. They tend to be rather useful and they are available both within standard definitions as well as within class methods. The syntax is as easy as:

with Ada.Text_Io;
use Ada.Text_Io;

procedure Hello is
   Hello_Text : constant STRING := "Hello World!";

   procedure Print_Hello is
   begin
     Put_Line(Hello_Text);
   end
begin
   Print_Hello;
end Hello;

Although the example is contrived, it does show how a nested routine can access a variable that is more global to the routine without having to make the variable global. This makes creating well contained modules, classes, and functions significantly easier using Ada.

There are dozens of aspects to Ada worth investigating, but I won’t go into more here. It is much better to check out a good book on Ada. This is especially true for understanding Ada’s type, module, and class system.

Ada 2005 Ada 2005 adds a number of new features and syntax worth noting, especially for those Java and C++ programmers looking at Ada for the first time. Other new features will appeal to current Ada programmers.

One of the major changes I found useful, being relatively new to Ada, is the change in syntax for calling object methods. Ada 95 syntax is:

   PackageP.method(ObjectX, parameters);

Ada 2005 syntax also allows:

   ObjectX.method(parameters);

Ada 95 started with the package name, but this is easily inferred by the object name (in this case ObjectX). The new syntax matches that used by Java and C++. While it may seem like a small thing, programmers hate to type more than is really necessary.

Ada 2005 also adds interfaces that are similar to Java interfaces. It addresses problems that are often solved using multiple inheritance in C++. Multiple interfaces can be combined as with Java.

One feature I really like with Ada 2005 uses the overriding keyword. It prefixes a method definition and indicates that the method should override one in the superclass. It is flagged as an error if there is no matching method to override. This typically occurs when an overriding method name is different due to a typing error. Without this type of feature, a class will simply include a new method that may or may not be used properly. It can wreak havoc if other methods call the old method when the new one should be used instead. Likewise, it is possible to use the not overriding keywords that guarantee the method does not replace an existing one. This can be very handy in finding problems when a superclass definition adds new methods that would then be improperly overridden by a subclass. Java and C++ would go along their merry way forcing the programmer to keep track of such changes. Unfortunately, these kinds of errors can be hard to detect and correct. Chalk up another Ada feature that reduces errors.

Ada 2005 incorporates a number of additional task-related enhancements to improve an already powerful multitasking environment. It now supports the Ravenscar profile. The profile was created for building safe and reliable real-time systems. It was defined in 1997 in Ravenscar, England at a workshop of international real-time experts. Ravenscar allows developers to prove early in the implementation cycle that nonfunctional requirements such as timing and ordering constraints are met. This is key to high-reliability systems such as those used in DO-178B environments.

A “short” overview of the Ada 2005 additions and changes is over 30 pages long, so a complete overview of these details is definitely beyond the scope of this article. It’s safe to say that there are even more significant enhancements as well as a host of useful, but more subtle, changes to Ada.

The one thing I can say about Ada 2005 is that it now compares very favorably to Java and C++ simply from a language standpoint. Add in its ability to reduce errors during development and you have a very interesting combination.

AdaCore 2005 The AdaCore 2005 compiler works with AdaCore’s GNAT Pro IDE (see figure) as well as an Eclipse plug-in (see “System Welcomes Ada 2005,” ED Online 10992). The GNAT Pro IDE is a self-contained development environment while the Eclipse plug-in works with an existing Eclipse installation.

Installation was the usual trivial exercise on Windows. I have not had a chance to check out the platform on Linux yet, and it also supports a range of other hosts including Solaris and OpenVMS.

The IDE is called the GNAT Programming Studio (GPS). It uses a compiler based on the GNU gcc compiler. There is a programming interface to GPS allowing plug-ins to be created or to allow applications to interact with the development environment. GPS supports a range of third-party products, including various source control systems.

GPS has the expected features such as multitabbed, syntax-directed editing; object and class browsing; refactoring support; project management; and revision analysis. It includes an interactive Python-based scripting system. There is a gdb-based visual debugger.

Overall, I found the GPS development environment comfortable and easy to pickup. It has a smoother feel than the Eclipse plug-in, but that is likely to change as the plug-in is refined. There is no lack of functionality with the plug-in, but as with most tools migrated to Eclipse, the first version just gets things working. Polish comes with subsequent updates.

AdaCore is not just a standalone compiler/debugger. It includes a large runtime package. It can handle chores from XML processing and pattern matching to multiplatform graphic support using GtkAda. It also has bindings to external libraries such as the Windows runtime.

Target platforms are somewhat limited. AdaCore supports VxWorks and LynxOS in addition to such host platforms as Windows, Linux, and Unix variants including AIX and Solaris. It can also target bareboard PowerPC systems.

AdaCore is not the only Ada provider, but it was one of the first with Ada 2005 support. They give you a choice of development environments and deliver a wide range of runtime options. I can definitely recommend this Ada development tool.

Final Thoughts Ada has significant advantages over Java and C++. Ada has deficiencies compared to these as well. In the latter case, one of the major issues is the availability of Ada programmers. I think there are two reasons for this. First, Ada has not been a popular language so it is not taught as widely as Java or C/C++. Second, because Ada is somewhat different syntactically and semantically, picking up Ada as another language has not been an easy task for programmers.

The demand for Ada programmers is growing simply to provide developers in the existing Ada-dominated environments, which will likely increase the availability of classes for Ada. With Ada 2005, Ada moves syntactically closer to Java and C++, making it easier for programmers with a background in these languages to pickup Ada. Likewise, Eclipse support will reduce the learning curve significantly, making it even easier to try out Ada.

Ada remains a major programming language even if the embedded world continues to clamor and stumble over C. While standards such as MISRA-C prune C to a better development target, Ada delivers the power of a complete, well-designed language. Most UML (Unified Modeling Language) implementations include Ada in their collection of target languages.

Hopefully this overview has provided enough tidbits to pique your interest in Ada. It may be time for you to give it a try.

Related Links AdaCore
www.adacore.com

Aonix
www.aonix.com

Artisan Software
www.artisansw.com

Eclipse
www.eclipse.org

Green Hills Software
www.ghs.com

GNU Ada 95
www.gnu.org/software/gnat/gnat.html

IBM
www.ibm.com

Libre Site (GNAT GPL)
http://libre2.adacore.com

Polyspace Technologies
www.polyspace.com

Sponsored Recommendations

What are the Important Considerations when Assessing Cobot Safety?

April 16, 2024
A review of the requirements of ISO/TS 15066 and how they fit in with ISO 10218-1 and 10218-2 a consideration the complexities of collaboration.

Wire & Cable Cutting Digi-Spool® Service

April 16, 2024
Explore DigiKey’s Digi-Spool® professional cutting service for efficient and precise wire and cable management. Custom-cut to your exact specifications for a variety of cable ...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!