datasheets.com EBN.com EDN.com EETimes.com Embedded.com PlanetAnalog.com TechOnline.com  
Events
UBM Tech
UBM Tech

Design Article

Comment


Mario Blunk

4/3/2012 9:17 AM EDT

Hi there,
I'm about to begin programming in a language other than assembly ...

More...



John Smith

2/7/2012 5:07 AM EST

This is a very valuable post, I found it looking through Google. I believe most ...

More...

High-integrity object-oriented programming with Ada - Part 1

Benjamin M. Brosgol, Senior Software Engineer, AdaCore

7/20/2011 8:11 PM EDT


Part 1 of this three-part article reviews the basics of object-oriented programming and summarizes the challenges it presents for high-integrity programming. Part 2 will provide a primer on the Ada programming language, and Part 3 will detail the tools Ada offers to help developers meet the OOP challenges.

The software development methodology known as object-oriented programming (OOP) has been available in programming languages for more than forty years. Although heavily used in many kinds of systems, OOP has not been widely adopted by developers of high-integrity software — i.e., where the highest levels of safety and/or security are required. This community has traditionally judged OOP’s benefits, such as component reuse and ease of maintenance, to be outweighed by its costs, which include personnel training, risks in moving to a new technology, and uncertainty on how to comply with safety or security certification. This situation is changing, however. With high-integrity systems growing in size and scope, OOP’s advantages in the design of robust and extensible software architectures are looking increasingly attractive. As a result, stakeholders such as regulatory authorities, software developers, and system integrators are focusing on how to use OOP safely and securely.

A specific and significant example is the avionics industry. The DO-178B safety certification standard1 is being adapted to address OOP issues, and the upcoming DO-178C standard2 contains a supplement3 with guidance on how to use object-oriented and related technologies while avoiding their vulnerabilities. Let's take a closer look at the basics of object orientation and the challenges OOP presents for high-integrity programming.

Concepts of Object Orientation
Object orientation is a software design and implementation approach that organizes a system around the kinds of entities (classes) that it deals with, and their interrelationships. The functions that the system performs are taken into account when designing the classes with which the functions are associated.

The essence of object orientation is embodied in three principal concepts: class, object, and encapsulation. A class is a language feature or combination of features that integrate a module, or unit of program composition, with a template for data instances. A class defines a set of members, which comprise the state (data fields) and behavior (invokable operations) of each instance. An operation has a signature (operation name and parameter specifications) and an implementation (code body). An object is an instance of a class. Encapsulation is the ability to restrict access to a class’s members, especially the state data, so that they are only available to those parts of the program with a need to know.

Systems can be designed with an object-oriented architecture if the programming language simply supports the concepts of class, object, and encapsulation, but the real power of object-oriented programming comes from several additional features: inheritance, polymorphism, and dynamic dispatching.

Inheritance is the ability to define a new class (the subclass) as an extension of an existing class (the superclass). The subclass implicitly includes the superclass’s fields, can add new operations and/or fields, and either implicitly inherits or explicitly overrides existing operations from the superclass. An inheritance hierarchy for a class consists of that class and all its direct or indirect subclasses.

Abstract classes are often useful as roots of inheritance hierarchies. An abstract class does not permit object creation. An abstract class can define abstract operations; i.e., operations with signatures but no implementation.

Inheritance in general is also called implementation inheritance, since the subclass implicitly inherits the state data of the superclass as well as the implementation of the superclass’s operations (unless overridden). If the superclass is abstract and sufficiently simple — no state data, and only abstract operations — then inheritance is known as interface inheritance (see figure 1). Such a class is commonly known as an interface. An interface may be regarded as a contract that needs to be fulfilled, or a set of operations that need to be implemented, by each non-abstract subclass.



Figure 1: This class diagram shows a class Node, an interface Encryptable, and a class DataNode that inherits from Node and implements Encryptable. DataNode implicitly inherits the Id field and the Set_Id and Id operations from Node, overrides Put and Get from Node, and implements Encrypt and Decrypt from Encryptable.

A subclass may exhibit single inheritance (only one superclass) or multiple inheritance (arbitrary number of superclasses). Languages vary in how these are modeled. For example C++ supports multiple implementation inheritance, while Ada, Java, and C# support multiple interface inheritance but single implementation inheritance.

Polymorphism is the ability of a variable to denote an object from any class in a given inheritance hierarchy. Dynamic dispatch (also known as dynamic binding) means interpreting an operation on a polymorphic variable as the version of the operation defined by the class of the object denoted by the variable at run time. In contrast, static binding means interpreting an operation on a variable as the version of the operation defined by the type (class) of the variable at compile time.

Proper use of OOP can make a system easier to implement and maintain, especially in dealing with new requirements, since adding a class to an inheritance hierarchy does not require changes or even recompilation of existing classes. However, OOP also introduces new challenges for software verification, especially when safety certification is required.




EREBUS

7/21/2011 4:09 PM EDT

It is a shame that more software people did not understand or use the benefits of Ada. I understand the desire to get to the coding quickly, but from my observations over the last 30 years, you get much better software faster with Ada then you will ever get from C or C++.

A major part of this failure lies with managers who want to see instant results rather than see a well thought out software design. If you build code without a good design, you get bad software. Many managers do not understand the true issues involved with software engineering versus coding. Coding is about 5% of the job.

I really liked the real-time support built into Ada. I have seen it implemented for complex real time avionics software and it does a very good job.

Hopefully, we can get some solid Ada compilers for the microcontroller market. The cost to generate good solid firmware would be greatly reduced.

Ada is an excellent way to build software. The problem is that it requires the developers to think before they code. Sadly, most are too undisciplined to take the time to build software correctly.

Oh well, maybe someday.

Thanks

Sign in to Reply



cdhmanning

7/25/2011 10:08 PM EDT

From what I've seen, Ada is just too limited to be completely useful for general embedded development.

Ada might be good for writing some parts of the code, but not all. It is hard to partition many systems into stuff to be written in Ada and stuff that should not.

Ada seems particularly unsuited to writing device drivers, interrupt service routines and such.

You can get GNAT for ARM and even AVR.

Sign in to Reply



UncleFin

7/26/2011 10:58 AM EDT

I am not sure what "general embedded development" is, but the orgainization I belong has used Ada as the primary language for many of our avionic systems - ranging from small high integrity controllers to flight management systems.

Sign in to Reply



cdhmanning

7/27/2011 10:46 PM EDT

I can write a complete system in C, with a few lines of assembler for the start up code etc.

Can you do that in Ada? From what I've seen Ada RTEs are written in C or such because Ada isn't flexible enough.

Sign in to Reply



Powernine

10/24/2011 10:39 AM EDT

About being adequate for general and embedded development you can do in ADA what you can do in C (eg bit manipulation) except that it is safer and cleaner. You can aslo do things you cannot do in C like controlling the address a variable is stored in. In C you have to use pointers and lose all "compiler protection". In Ada you can do like that but haven't to and shouldn't to.

About RTEs the reason is because ADA vendors cut costs by using preexisting libraries and these are, unfortunately because they are a source of bugs, in C.

Sign in to Reply



Aaron451

8/4/2011 5:30 PM EDT

I used Ada '83 for several years do hard-realtime software (motor control) with great success. Now I do the same thing in 'C' and with for the Ada tools. It took a bit of time to learn, but once I got it down coding went fast and debugging was almost an after-thought. AND REAL code reuse was in the 80% range from project to project.

Sign in to Reply



Dixy3

7/21/2011 8:43 PM EDT

EREBUS, I totally agree with you, managers are always looking to cut corners to save on costs rather than have the best quality code for the job. Ada as a lot to offer given time for programmers to develop good code without additional pressure from their managers to complete the programming job like yesterday. May be it is time for someone to write a free Ada IDE for microprocessors like ARM and Arduino so developers and programmers can play at home on development boards and then start to use Ada at work in a more commercial environment? Ada I think would also be ideal for areospace nano satellites like CubeSats given the chance to develop it.

Sign in to Reply



Niklas Holsti

7/24/2011 2:59 PM EDT

Links in reply to Dixy3:

GNATDroid, a version of the GNU Ada compiler GNAT for Android: http://www.dragonlace.net/

AVR-Ada, a version of GNAT for the Atmel AVR chips: http://sourceforge.net/projects/avr-ada.

and the trump: an Ada compiler that generates C code and thus targets any system that has a C compiler: http://www.sofcheck.com/products/adamagic.html

The AdaMagic compiler is being used for a CubeSat project, I believe.

Sign in to Reply



cdhmanning

7/27/2011 11:14 PM EDT

If you really want to play, there's Ada for Lego Mindstorms robots...

http://libre.adacore.com/libre/tools/mindstorms/

Free download.

This runs on a small ARM micro and should be readily portable to other small ARM systems.

The Mindstorms Ada environment seems to use the Lejos code as its underpinnings. That is written in C.



Sign in to Reply




John Smith

2/7/2012 5:07 AM EST

This is a very valuable post, I found it looking through Google. I believe most readers will agree with your views. Finally – a person with common sense!

http://www.zuneauto.com

Sign in to Reply



Mario Blunk

4/3/2012 9:17 AM EDT

Hi there,
I'm about to begin programming in a language other than assembly and shell programming. I'm also used to code hardware designs in Verilog HDL.
So I'm asking myself whether it is useful for me to start right with ADA and ignoring all the C/C++/Java... My mind has not been "spoiled" with this stuff :-) So what do you guys recommend ?

Sign in to Reply



Please sign in to post comment

Navigate to related information

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)