Tutorial: Unleash the power of Ada Generics

Gautier de Montmollin, Ada-Switzerland, Switzerland

Generics, known elsewhere as templates or macros, form an abstraction that is prosaically a smart version of a text with gaps, which helps to eliminate code duplication. The Ada flavor of generics, available since the first Ada standard (1983), is remarkably powerful:

  • The list of formals (the placeholders for the gaps) can contain one type (like in some languages) but also zero or many of them;
  • The information on the types can be of various levels;
  • Other kind of programming items like constants or subprograms can also be part of the list;
  • Generics and/or their instantiations can be nested – possibly inside other generics!

Beside their role in code simplification, generics can also be used for purposes that do not always come to mind, for example:

  • Simulating various alternative encodings for a data compression scheme,
  • Selecting image sub-formats during their decoding

In both of those cases, the motivation is performance, although in the former case, a better readability is also achieved on the way.

We show through those examples how to unleash the power of Ada generics.

Presentation topics

  • Refresher on Ada generics
  • Squeeze data with the LZMA compression scheme using generics
  • Boost performance of an image decoder

Duration: half-day

Level: Basic knowledge of macros / templates / generics

Reason for attending

Discover possibly unusual programming techniques with Ada generics.

Presenter

Gautier de Montmollin is a software developer. He holds a PhD in mathematics from the University of Neuchâtel, Switzerland. His quest for both run time and development time efficiency has trapped him with the Ada language which he has the luck to use professionally (formerly in finance, now in robotics) and for private projects as well. He has presented professional and private projects at various Ada-Europe and FOSDEM conferences.