473,805 Members | 1,939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Teaching new tricks to an old dog (C++ -->Ada)

I 'm following various posting in "comp.lang. ada, comp.lang.c++ ,
comp.realtime, comp.software-eng" groups regarding selection of a
programming language of C, C++ or Ada for safety critical real-time
applications. The majority of expert/people recommend Ada for safety
critical real-time applications. I've many years of experience in C/C++ (and
Delphi) but no Ada knowledge.

May I ask if it is too difficult to move from C/C++ to Ada?
What is the best way of learning Ada for a C/C++ programmer?

Jul 23 '05
822 29868
xpyttl wrote:
"Preben Randhol" <ra************ *************** ****@pvv.org> wrote in
message news:42******** @news.broadpark .no...
C++ programmers will claim to their death that they are infallible and
everybody else isn't. However, none of them seem to understand how

ignorant
they are...


And this is different from Ada programmers how?

There are obviously two groups here. First, there are the Ada guys who
seem to think that modern C++ is the same language Dennis Ritchie invented
30
years ago. Then there are the C++ guys who view Ada as a sort of military
style Cobol.

The two camps are equally close to the truth.


I fall into the third camp.

Now, I know a lot of people who do use C, C++, Ada and Java in mission
critical systems and do so successfully. Most of them use some form of
checking tools (even the Ada guys). It is certainly a long way from the "if
it compiles it is right" attitude that has seemed to have been purported by
just a very few of the Ada crowd here.

I have always held that the language used is immaterial to the safety of
final product (I certainly stated it often enough here and in c.a.e). I
acknowledge that some things can be made easier or harder by language
choice. However, it is mainly in the development process you use where the
integrity of the product is nurtured and the evidence of successful
development is produced.

--
*************** *************** *************** *************** ********
Paul E. Bennett ............... .....<email://pe*@amleth.demo n.co.uk>
Forth based HIDECS Consultancy .....<http://www.amleth.demo n.co.uk/>
Mob: +44 (0)7811-639972
Tel: +44 (0)1235-811095
Going Forth Safely ....EBA. http://www.electric-boat-association.org.uk/
*************** *************** *************** *************** ********
Jul 23 '05 #271
xpyttl wrote:
"Preben Randhol" <ra************ *************** ****@pvv.org> wrote in
message news:42******** @news.broadpark .no...
C++ programmers will claim to their death that they are infallible and
everybody else isn't. However, none of them seem to understand how

ignorant
they are...


And this is different from Ada programmers how?


That's certainly an exaggeration about C++ programmers,
but it's not even close to an Ada programmer. An Ada
programmer likes Ada because he/she knows he/she is NOT
infallible.

--
Wes Groleau
-----------
I've been framed! ...
http://www.useit.com/alertbox/9612.html
Jul 23 '05 #272
Jim Rogers <ji************ **@att.net> writes:
Yes you can. You can always program in your own checks manually.
The drawback of doing that is that you cannot simply turn them off
with a pragma, nor can the compiler so effectively optimize those
checks out of your program when they are unneeded.


Ada compilers can optimize away manually-programmed checks as well as
built-in checks. Whether it can do so in any particular situation
depends on the code -- how much information is available to allow the
compiler to prove things -- but not so much on whether the checks are
built in.

Likewise, C++ compilers can optimize away manually-programmed checks in
some cases.

- Bob
Jul 23 '05 #273
"Jerry Coffin" <jc*****@taeus. com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
....
So far, no C++ advocate seems to have said anything similar to what you
claim, but in a way you're probably right. If we depended on Ada to do
the job, the Internet (for one) would be drastically more secure,
though only because nobody used it! :-) (<- explicit smiley for those
who seem to need them...)


With or without the smiley, your comment is just the kind of unsupported
anti-Ada stuff that we see all the time. Why would the Internet not be used?
Ada is a fully general purpose programming language, and if the Internet was
mostly written in Ada, the applications and uses would be pretty much the
same (just with fewer trivial bugs).

The web server and search engine we run are completely written in Ada; our
mail server is partially written in Ada. As a client, you won't notice any
difference (other than the slowness of being behind a fairly slow Internet
connection).

Randy Brukardt

Jul 23 '05 #274
REH

"Ed Falis" <fa***@verizon. net> wrote in message
news:opsnfw9nx7 5afhvo@localhos t...
On Thu, 10 Mar 2005 15:55:17 -0500, xpyttl <xp***********@ earthling.net>
wrote:
The two camps are equally close to the truth.


Fortunately, it mostly hasn't been that bad as language debates go ;-)

- Ed


I have been following this thread with great interest. C++ is by far my
favorite language, but use Ada almost exclusively at work. I love C++, but
I would not relish creating a large-scale, fault-tolerant system in it,
especially involving a large team with varying levels of skill. This thread
has been surprisingly civil with only one or two individuals using childish
attacks and half-truth to argue their side (I won't say which). Though, I
had to cringe when some in the C++ camp attempted to argue its safety vs.
Ada. I would not, myself, attempt that argument. I think its a great
language, and gives you a lot of flexibility that you can build safety upon,
but does not inherently come that way. On the other hand, it takes effort
to write an Ada program that will crash. If it compiles, it will usually
run. It may not do what you intended, of course, but it won't "core dump"
or cause a reboot, etc. Although I have to admit, I prefer C++'s OO model.
I find it easier (personally) to see the encapsulation, and Ada's
dispatching rules still confuse my. Can someone explain why they chose the
package as the encapsulation level for a class?

Ada features I would love to have in C++:
* "new types" and sub-ranges
* runtime template instantiation (I think being able to instantiate generics
dynamically is the coolest thing!)
* subprograms inside subprograms. I think it would be great for use with
the STL (i.e., using a local function with std::foreach)
* packages. namespaces are nice, but packages make modularity of very large
system a lot easier. Especially now with "use type"
* representation specifications! !!!

C++ features I would to have in Ada:
* Implicit instantiation. Yeah, I know, it can be unsafe, but that is one
thing I really like about C++: the ability to automate repetitive things.
* actually having a class object encapulating the data and methods.
* reference (in out) types in functions (without resorting to access types)
* meta-templates. very neat stuff. ugly, but neat.
* The STL!!! (though I hear something similar is coming?)
Jul 23 '05 #275
CTips <ct***@bestweb. net> writes:
- Usually the checks will be added every place they are needed, and then
the usual optimizations will be used to eliminate them. In other words,
if one adds the checks manually, the compiler should eliminate them
identically.
That's true in cases where the manual checks are equivalent to the
built-in checks. But there are important cases where they're not. For
example, if you pass an integer as a parameter, and inside the called
procedure use that as an array index, it is typically natural to declare
the integer parameter as a subrange whose bounds match the array bounds
(even if those bounds are dynamic). So the array-indexing check can be
optimized away. C++ has no integer subranges, so if you did the
equivalent in C++, with a manual check, the compiler could not normally
optimize it away.

OTOH, I suppose you could program integer subranges in C++ using
templates.

You are correct that Ada's run-time checks are not entirely free in all
cases. In order to check the bounds, the bounds must be stored in
memory, which is a cost. And even if the checks are suppressed, I don't
know of any Ada compiler that will avoid storing the bounds. This is
partly because in Ada you can query those bounds (Some_Array'Len gth, for
example). On the other hand, if you're querying the bounds, the
equivalent in C++ would have to store the bounds, too.
How easy is it to build an arena allocator in Ada?
Pretty straightforward . You write a package containing a "storage pool
type", with operations like Allocate (which returns an Address).
You then attach your storage pool to particular pointer types,
and then the generated code will call your operations instead of the
compiler-provided ones. Inside your storage pool code, you will no
doubt have to do all kinds of low-level stuff -- address arithmetic,
perhaps. Ada has plenty of support for that level of coding.
Given a processor with load-word-locked and store-word-conditional, how
would I build an atomic increment function?


Use a machine-code insert. Same way you'd do it in any language, I
suppose. And wrap it in an abstraction layer so you can have some hope
of porting to a machine without those instructions.

- Bob
Jul 23 '05 #276
"Jim Rogers" <ji************ **@att.net> wrote in message
news:4%******** *************@b gtnsc05-news.ops.worldn et.att.net...
Jim Rogers wrote:

I would have done this program somewhat differently.
with Ada.Text_Io;
with Ada.Numerics.Di screte_Random;

procedure Random_Fill is
type Rand_Values is range 0..10_000;
package My_Rand is new Ada.Numerics.Di screte_Random(R and_Values);

Seed : My_Rand.Generat or;
subtype Index_Type is Natural range 1..1000;
Vec : array(Index_Typ e) of Rand_Values;
Found : Natural := 0;
begin
My_Rand.Reset(S eed); -- seeds the random number generator

-- fill the array with random values in the range of 0
-- through 10,000
for I in Vec'range loop
Vec(I) := My_Rand.Random( Seed);
end loop;
Much better to use an aggregate here:

Vec := (others => My_Rand.Random( Seed));

The random function will get called once for each component. Let the
compiler write the loop; it can't do a worse job, and it might actually do
better.
-- finds first index where a value is less than 1000
for I in Vec'range loop
if Vec(I) < 1000 then
Found := I;
exit;
end if;
end loop;
if Found > 0 then
Ada.Text_Io.Put _Line("Number < 1000 found at index" &
Natural'Image(F ound));
else
Ada.Text_Io.Put _Line("No number < 1000 was found");
end if;
I generally stick a test for 'Last into the loop. But that's more because
I'm lazy.

-- finds first index where a value is less than 1000
for I in Vec'range loop
if Vec(I) < 1000 then
Ada.Text_Io.Put _Line("Number < 1000 found at index" &
Natural'Image(I ));
exit;
elsif I = Vec'Last then
Ada.Text_Io.Put _Line("No number < 1000 was found");
exit;
end if;
end loop;

But in this case, you really ought to not use a for loop at all:

declare
I : Index_Type'Base := Vec'First;
begin
while I <= Vec'Last loop
if Vec(I) < 1000 then
Ada.Text_Io.Put _Line("Number < 1000 found at index" &
Natural'Image(I ));
exit;
end if;
I := I + 1;
end loop;
if I <= Vec'Last then
Ada.Text_Io.Put _Line("Number < 1000 found at index" &
Natural'Image(I ));
else
Ada.Text_Io.Put _Line("No number < 1000 was found");
end if;
end;

But of course this is a bit more prone to errors.

The best plan is to use a container function that does the searching, so you
don't have to.

That's probably more on this topic than anyone wanted to know. :-)
end Random_Fill;


Randy Brukardt

Jul 23 '05 #277
xpyttl wrote:
Then there are the C++ guys who view Ada as a sort of military
style Cobol.


COBOL _was_ military...well Navy at least :-)

http://www.greatwomen.org/women.php?...=viewone&id=79


Jul 23 '05 #278
Martin Dowie wrote:
xpyttl wrote:
Then there are the C++ guys who view Ada as a sort of military
style Cobol.

COBOL _was_ military...well Navy at least :-)


The inventor of COBOL reports basket ball as a major
influence (passing indiretly). And the effect of
private account balancing on the choice of number
systems (Oops, summed the spendings in octal...).
Georg
Jul 23 '05 #279
REH wrote:

C++ features I would to have in Ada: * The STL!!! (though I hear something similar is coming?)


See, for example,
http://www.ada-auth.org/cgi-bin/cvsw...s/AI-20302.TXT
Jul 23 '05 #280

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
2366
by: Mediocre Person | last post by:
Well, after years of teaching grade 12 students c++, I've decided to make a switch to Python. Why? * interactive mode for learning * less fussing with edit - compile - link - run - debug - edit - compile - link - run -..... * lots of modules * I was getting tired of teaching c++! Bored teacher = bad instruction.
14
1828
by: Gabriel Zachmann | last post by:
This post is not strictly Python-specific, still I would like to learn other university teachers' opinion. Currently, I'm teaching "introduction to OO programming" at the undergrad level. My syllabus this semester consists of a bit of Python (as an example of a scripting language) and C++ (as an example of a compiled language). With C++, I go all the way up to meta-programming. My question now is: do you think I should switch over to...
3
1538
by: andy_irl | last post by:
Hi there I have been asked to teach HTML to a group in our local village community. It is nothing too serious, just a community development grant aided scheme. It will be a 10 week course of two hours per week and will mainly consist of mature students. I may or may not include GUI's depending if I can fit it all in to the time allocated. I was wondering if anyone could point me to any useful teaching resources for HTML on the web ie...
12
2004
by: Pierre Senellart | last post by:
I am going to teach a basic Web design course (fundamentals of HTML/CSS, plus some basic client-side (JavaScript) and server-side (PHP, perhaps XSLT) scripting). Most of the students do not have any previous knowledge of all of this. I am strongly considering teaching XHTML 1.0 Strict instead of HTML 4.01 strict, for the following reasons: - XML syntax is far more simple to teach than HTML/SGML, simply because there are not as many...
16
4379
by: msnews.microsoft.com | last post by:
I am teaching C# to my 11 year old child. One challenge is that all the C# books I own and that I have seen in bookstores are full of language that is not easily comprehended by a student at that age. Can anyone recommend books (or perhaps websites) tuned for younger audiences? BTW, its amazing how fast a student can absorb this kind of information at that age. Lucky them! Thanks, Bruce
24
2867
by: Richard Aubin | last post by:
I'm really new to vb.net programming and programming in general. I would like to teach myself on how to program effectively and I have the financial and time resources to do so. Can I anyone recommend and point me in the right direction where I should start? -- Richard Aubin
0
1720
by: e.expelliarmus | last post by:
check this out buddies. kool website for: * hacking and anti hacking tricks * anti hackng tricks. * registry tweaks * orkut tricks * small virus * computer tricks and loads of different tricks... www.realm-of-tricks.blogspot.com www.registrydecoded.blogspot.com
1
3897
by: JosAH | last post by:
Greetings, Introduction This week's tip describes a few old tricks that are almost forgotten by most people around here. Sometimes there's no need for these tricks anymore because processors nowadays are so fast and memory comes in abundance. But still, if we implement an algorithm that is better, or more efficient, than another one, those faster processors run the first algorithm faster than the other one. If an algorithm takes less...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4323
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.