Showing posts with label ADA. Show all posts
Showing posts with label ADA. Show all posts

2017-11-12

Ada

I did say I was trying to learn Ada.

Well, I thought I would explain that it is a bit stalled, sadly.

I have managed to read a lot of the Barnes book on Programming in Ada 2012. Well, over half anyway. I read a lot whilst on a cruise!

It is a tad more verbose than I am used to, but overall I would have to say it does look good. The very strong typing, and the fact that all types allow value range controls, all make for much safer code. Even the multi-tasking looks interesting.

I have got to the stage that I would like to try using it, and that is where I have come unstuck, sadly.

Obviously, if I wanted to simply code some abstract program, much as one would on a Computer Science course, then of course I could use Ada. Sadly, such simple self contained abstract programs with no more than basic text input and output are pretty much academic now. Nobody does INPUT and PRINT to communicate to the user, they use a range of libraries, web sockets and web pages, javascript, all sorts. And that is just the user side, the back end is all libraries for mysql, or B2B XML, or libcurl, or something else.

A lot of the code I work on, and code I start from scratch even, is run on a linux environment. I have a load of our own C libraries which we use extensively, but of course linux has a lot of C libraries that are used for all sorts of things. I am not against re-working our own libraries - some of the key ones are XML manipulation and SQL front end for the standard client library. I am sure both can be done in Ada with no problem, but I am not re-working OpenSSL from scratch in Ada.

The problem is that to use these from Ada I would have to find or code interfaces or new libraries. That is going to make a huge hurdle for any code I need to write. I get the impression that there are some Ada wrappers and libraries available, but I am struggling to find them.

I mean, is there an Ada library for mysqlclient interface, or openSSL for TLS? Heck, what about something really simple to start with like popt library? There must be a good Ada XML library?! If I can find libraries or wrappers for a large list of key functions that we use regularly on linux then maybe I can start using Ada, but right now it is not looking promising.

There is one closed project we work on, and have for many years. It is a project where every library and functions is written from scratch, including the operating system. It was suggested long ago that maybe we should use Ada, and I decided against it. In hindsight maybe that was a mistake, as it would have been a perfect case where we did not rely on any external systems and could have started from scratch in Ada. That project is the FireBrick. There is even some chance we may start using some Ada modules in future... But that would have been cool - a complete operating system from scratch all based on Ada. I am kicking myself for not doing that when we started now. Sorry Cliff.

If I do make more progress, I'll let you know, but for now it is stalled.

2017-08-02

Ada

This is likely to be the first of a series of blog posts over some months.

I am planning to learn Ada. For those that do not know, Ada is a programming language.

Why? Well, why not? I like to expand my skills and knowledge, and it is a good language.

I have used many many programming languages over the years, high level, object oriented, and even some very "special" ones like postscript and ps-algol. I have done a lot of assembler in a range of processors. However, at the end of the day my go-to language is C, more specifically GNU C (as it has a few invaluable extensions to normal C).

I like C for several reasons. It makes it very easy to work at a low level with the compiler generating code that you expect - or does it? Sadly, times have changed. Once upon a time I could tell you what the compiler is doing - but there have been two key changes. One is some very smart optimisation in compilers, and the other is the way processors (even relatively simple ones like ARM) pipeline and cache things. The combination of the two is a compiler that knows that some things that seem obvious are not so, because of the way the pipelining and caching work. You can end up with compiler output that is quite confusing to understand, but ultimately rather good. You almost have to consider RAM to be a slow peripheral these days, which is a new way of working for me.

I also like C because of the way it allows me to access bits and bytes as I want, or does it? The big and little endian nature of processors matters, and so does the way they handle 32 bit for 64 bit registers. C has types which you cannot always tell are as specific size. Indeed, in the FireBrick code we have types like ui8 and ui32, and so on, so we know exactly what we are dealing with. You can do that with C if you try.

I also like C because all of the libraries in linux, where I do most coding, all work with C interfaces and include files. This remains true and is actually a stumbling block for learning any new language. To be honest, the FireBrick code would probably have benefitted from being done in Ada from scratch as we do not have an existing operating system - we have our own. Sorry to Cliff who did suggest that when we started the latest design (FB2700, etc) - maybe it would have been a good idea.

So, I have started, and Ada is basically a simple procedural language like C, not fundamentally different in concept. Well, to start with. The syntax is different, and in some ways more verbose / wordy. So far it seems to have some very nice features. The data object definitions and very strict typing are excellent, and something we should all use (GNU C is not too bad at some of that). The explicit mapping of data to binary structures is nice too. A nice thing is the option for a shitload of runtime checks, including data types with strict ranges.

It also has good exception handling, which is useful in any system. It also has a multiple threaded operation and scheduling as part of the language - awesome!

My understanding is that Ada suffered from being the recommended, or even mandated, language for military projects, and so people steered clear of it. That is a shame.

Another point that appeals is that it is not a stagnant language - Ada 2012 is the latest version (I think). With C, you have C99 and GNU C, but it is not a progressing and updating language in the same way.

So far I have read a lot, and done the obligatory "hello world" program. I need to read more, and code more. There is a lot to actually learning a language. Far more than the Computer Science degree stuff - you have to really understand it in practice and be able to use it properly in an operating system environment. I have to find code I can make in Ada, and that is where the fun starts.

I work a lot in a linux environment. Lots of standard libraries, from mysql, to tls/ssl, and I use them. I need "bindings" to allow these standard libraries to be used from Ada rather than C. That is likely to be where the work lies.

So, reading a book and playing with code while on holiday next week I expect, and I'll report back. Can I "embrace" Ada as a language, or will this be a small diversion and intellectual exercise, or will I just forget it and watch TV? Yet to see.

QR abuse...

I'm known for QR code stuff, and my library, but I have done some abuse of them for fun - I did round pixels  rather than rectangular, f...