Emmanuel Briot has published an interesting extension to my usual guidelines (happily stolen from the Quality and Style Guide) on declaring tagged types.
Basically the pattern is (in my version):
subtype Parent is Parent_Type_Package.Instance;
type Instance is new Parent with private;
subtype Class is Instance'Class;
type Reference is access all Class; -- Optional, only if you really need access types
What do you think of it?
And do you prefer Emmanuel’s naming style or mine?
If you want to learn a bit about types and the Static_Predicate aspect in Ada 2012, then this AdaCore gem has the good stuff:
Ada 2012 is full of features for specifying a rich set of type properties. In this series of three Gems, we describe three aspects that can be used to state invariant properties of types and subtypes. This first Gem is concerned with the Static_Predicate aspect.
With the Static_Predicate aspect you can do cool stuff like this:
type Day is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
type T_Day is new Day with Static_Predicate => T_Day in Tuesday | Thursday;
Nice eh’? The compiler will now protect you against assigning Friday to a T_Day. That is pretty neat. Stay tuned for part 2 and 3, where more of the Ada 2012 goodness will be explained.
Those of us who are gamers at heart, know that Id Software usually release their “old” games and tech as open source, and naturally that also happened for the Doom 3 game. This in itself is good news, but what is even better is the fact that efforts are being put into an Ada port. The man behind the project is only known to me as J JS, and he is hosting the project at the AdaDoom3 GitHub repository.
A few posts has been made about the project at the Ada Programming Community:
Feel free to pop in and join the Doom fun!
In an article aptly named Ada 2012: Ada With Contracts we get a very nice presentation of the new Ada 2012 facilities for contract-based programming.
The most recent version of the Ada standard, known as Ada 2012, brings contract-based programming to a mainstream language. Preconditions, postconditions, type invariants, and subtype predicates allow software developers to specify their programs’ intent more clearly, in effect embedding requirements into the source code. This feature makes it easier to review and understand the program, and it facilitates verification by the compiler, static analysis tools, and/or runtime checks.
I’ve used these new-fangled shinys a bit, and they are nice. Very nice actually. There’s just something truly awesome about being able to add pre/post-conditions to your method specification. The extra level of information and protection against errors is pretty amazing, and it is so darn easy to work with.
If you haven’t already tried your hand at these new features, be sure to do so. As the article says at the very end:
…the techniques of contract-based programming represent a significant advance.
I wholeheartedly agree.
I’m a pretty big fan of R. Tyler Croy because his articles are always well-written and to the point, and his latest addition to the interwebs is no exception: Safe, Dynamic Task creation in Ada.
A few years ago, Ada become my hobby/tinker programming language of choice, for a number of reasons, concurrency being one of them. In this post I’d like to walk you through an example of dynamic task creation in Ada, which uses Ada.Task_Termination handlers, a new feature in Ada 2005.
The article is packed with neat little snippets of code for maximum entertainment value. It’s a good read if you’re interested in seeing Ada.Task_Termination in action.
Here’s hoping we wont have to wait forever before mr. Croy gets busy on his next Ada programming article.
Our very own Jacob Sparre Andersen is doing a course on Parallel Ada programming for sequential programmers at Open Source Days 2013:
Assuming you already know sequential programming in a procedural programming language, this course can get you started writing parallel programs using the Ada programming language.
Short and sweet. The course contents are as follows.
- A quick introduction to the basics of sequential programming in Ada. — Just enough to allow you to map your existing programming knowledge to Ada. 45 minutes lecture + 45 minutes exercises.
- Creating and understanding basic tasks (parallel threads of execution) with Ada. — I.e. parallel programming without interaction. 45 minutes lecture + 45 minutes exercises
- Communication between tasks using safe, shared objects. One kind of interaction between tasks. 45 minutes lecture + 45 minutes exercises
- Direct communication between tasks using rendezvous. — Another kind of interaction between tasks. 45 minutes lecture + 45 minutes exercises
- Patterns for implementing parallel execution. 45 minutes lecture
I’m so going. Next step: Getting an Open Source Days 2013 ticket.
Today I found a great new website: flyx.org. It is the personal website of Felix Krause and on this website I found a gem of Ada programming magic:
It is a great article if you want to get into the art of binding to C libraries:
This article gives an overview over problems, solutions and guidelines for writing an Ada binding for a C library. It summarizes experiences I made while implementing OpenCLAda and OpenGLAda. Code examples are taken from those projects.
The Ada code examples shown here are written in Ada 2005. Note that you can import C functions somewhat nicer in Ada 2012.
Since I’m a complete binding virgin, I would like to personally thank Felix Krause for writing this article. I’ve learned A LOT from reading it. I also added the article to the Ada-DK wiki Resources page.
First allow me to apologize for the quiet of lately. I’ve been very busy these past months, so Ada programming news has been left to flounder. I can’t guarantee anything, but I will try my best to get the Ada-DK news-stream flowing again.
With that out of the way, lets move on to more important matters: The two new articles that has been added to our wiki:
The author of both articles is our very own Jacob Sparre Andersen. I’d just like to say this one thing: YAY! It’s always great when more authors join the wiki effort.
And remember: Don’t be shy if you spot errors or if you’d like to add something to the articles; it is a wiki after all, so pitch in if you like.
Qunying Zhu, the man behind the blog Z’s space, have started the momentous task of moving the AdaTutor program created by John Herro and Karl Nyberg to the web.
AdaTutor is an Ada 95 tutorial program written by John J. Herro. It has been placed into public domain by John. It is a great tutorial although it only touches on Ada 95 and does not contain information for Ada 2005 and 2012.
Here I have the AdaTutor presented on this blog. You will still need to download the AdaTutor to fully making use of this tutorial, as some contents and assignment information are not in the tutorila directly.
If you want to run the tutor under Linux, this article AdaTutor – Running it in Slackware will give you an idea. Although it is mentioned for running it under Slackware, the procedure does not involve any distribution specific feature, it could apply to common Linux distributions with GNAT compiler.
AdaTutor @ Z’s space is good work, and I’ve promptly added it to the Ada Resources page at the Ada-DK Wiki. Of you’re new to Ada programming, then be sure to pay this excellent resource a visit.
From Adalog we get news of the latest AdaControl 1.14 release:
Adalog is pleased to announce the release of AdaControl 1.14. As usual, this release features new controls (meter says 421!), new features, bug fixes.
More importantly, it compiles with Gnat GPL2012! A change in the ASIS interface prevented the previous version from compiling with the latest versions of GNAT. AdaControl is now provided in two flavors, one for the “old” GNAT, and one for the recent one. Features are the same, except that some controls related to Ada2005/2012 are not available with the “old” version.
Here’s a short blurb about the functionality of AdaControl:
AdaControl is a free (GMGPL) tool that detects the use of various kinds of constructs in Ada programs. Its first goal is to control proper usage of style or programming rules, but it can also be used as a powerful tool to search for use (or non-use) of various forms of programming styles or design patterns. Searched elements range from very simple, like the occurrence of certaine entities, declarations, or statements, to very sophisticated, like verifying that certain programming patterns are being obeyed..
Which elements or constructs are searched is defined by a set of rules; the following table gives a short summary of rules currently checked by AdaControl. The number in parentheses after the rule name gives the number of subrules, if any. Considering all possible rules and subrules, this makes 421 tests that can be performed currently by AdaControl!
Whenever I read about AdaControl, I think to myself “you really ought to learn how to use this tool”, but for some odd reason I never get around to it, and I’m absolutely sure my code suffers from it. Poor code.