Monday, November 10, 2008

Learn Ada, not C++.

Its common these days for students to learn C++ , and many apps are indeed written in C++ as a side effect of the above endless circle.

However, The truth is C++ is not all that great really.

**But why Ada..**

Over the next few blogs I am going to just throw(hehe) out a few examples and you can see for yourself.

The important thing here is to learn both before making calls on what is better for what. Clearly everything has its place. Although its good to know a little more then just past your nose ;)

Here goes...

Exception handling;

As you know exception handling consists of three components, the
exception (derr), raising the exception and handling the exception.
However, In C++ there is no exception type. When you raise an
exception you pass out any sort of type while selecting the exception
on its type. In Ada, there is a 'psuedo-type' for exceptions.

So here is some example code:

In C++

try {
} catch (declaration) {

In Ada

 when ident => clean_up();
 when others => clean_up();

OK, now here is a example where we call a function which we know may
raise a particular exception. Although it _may_ raise one that we
don't know about so we *must* pass everything else back up to whoever
called the function.

try {
} catch (const char* string_exception) {
 if(!strcmp(string_exception, "what_we_are_look_for")) {
} else {
} catch (...) {

OK, now in Ada:

 when what_we_are_look_for => handle_it;
 when others => raise;

Yes it even looks better !

This shows how much safer the Ada version is, we know exactly what we
are waiting for and can immediately process it. In the C++ case, all we
know is that some kind of exception occured of type 'const char*' had
been raised, we must then check it still further before we can handle

it !

I will try to keep these short, so that is it for now.


Edward O'Callaghan.

1 comment:

Ivan Levashew said...

Your C++ sample makes no sense. C++ programmers never write things like this. If you want to spot the real problems, consider following this link:

Your try, however, isn't worthless. I'd like more post like yours to appear on the Web.

Your post is addressed to developers, but developers are not necessarily the moving force. You should talk with consumers (i. e. non-programmers) as well. Tell them what are the consequences of using C++ software. Tell them that cellphone viruses became true because of C++ developers. Remind them that integrity of C++ programs is "all or nothing". A tiny single bug might crash or exploit the whole application. Show them that moving from unsafe C++ to safe Ada is as natural as moving from unsafe FAT32 to safe NTFS.

People then find out that there are no Ada replacements for most software they use. Tell them what to do: "AVOID PAYING FOR C++ PROGRAMS. IF YOU CAN'T LIVE WITHOUT THIS PROGRAM, PIRATE IT AND BE HAPPY." People often think that Windows users should have license for it. Tell them they'd not. Every Windows license prevents progress from happening. Microsoft has stated for a long time that their products are safe. And continued writing in C++. They've developed .NET Framework, but its core is in C++, not in Ada. As result, .NET Framework is getting critical updates as well as any other C++ software.

Why should consumers be more honest than producers?

"You pleasure yourself writing in C++ and provide us imaginary safety -- we pleasure ourself using your software and provide you imaginary money" -- that's the deal.

Just a mere sample of how anti-C++ post should look like.