Ada advocacy ­— Ada promoting missions — any proposals?

2 Likes

Ada ranks #4 on energy efficiency:

http://scribe.esmail5pdn24shtvieloeedh7ehz3nrwcdivnfhfcedl7gf4kwddhkqd.onion/codex/what-are-the-greenest-programming-languages-e738774b1957

Unfortunately the Ada-Java spread in that study is too tight to make a case for Ada smartphone apps saving on battery power.

Lets face it; Ada is just about 40 years old now. She is not as attractive as she used to be for the newer generations… For year she has worked relentlessly on hard and complicated tasks; but oh so complex with all her focus on getting things done in the right order all correc before the deadline, very strict with all her safety and integrity. And always looking back decades forever gone…

time for non realtime non system ada? a spinoff language anyone…? look forward, envision…

Note for TIOBE that the “based on the number of skilled engineers world-wide, courses and third party vendors” statement is a pure guess-work from the index’s author. The index works by searching “X programming” for language X on various search engines. This is a good idea per se, but the induction that it is for instance related to the number of skilled engineers is pure bluff.
For those interested, I have made an automated version of the TIOBE index - in Ada of course:

1 Like

And another thing to realize: for a similar sized user base, a search of “X programming” will find many more hits if there are lots of problems using the X language, related to how good/consistent/well-defined that language is. So a higher TIOBE score for X might also indicate there are more problems with X…

1 Like

That energy efficiency study is wildly misleading. A case for energy saving on phones couldn’t be made anyway because often the screen is on without processing. The Signal and whatsapp ratchet algorithm is woefully inefficient due to the expense of frequent ecdh but no-one cared. Certainly a security case could be made but it looks like Google are adopting Rust. I don’t know how to tackle that which I do not understand. Documentation has improved and should help but why do people prefer using * and & for pointers, never mind the pointers themselves. It really isn’t “concise”.

For some reason the IEC 61131 languages do not seem quite to make it… I do not know how many lines or how many engineers or if it is trending or not but I dare to say the language(s) has influenced our society…

What do you mean “non realtime non system” a general computer language must deal with these problems. Yes I can think of some improvements but perhaps it’s time to actually reach out to people and bring them into Ada rather than pretend that they will just arrive of their own accord. Make sure that the tools work with the reliability that Ada claims to support see my topic “Starting Ada - It has to work” rather than throw all the good stuff away. Ada should support the integrity that Rust seems to offer as standard. I will support a new branch of Ada but with more integrity and for sure indexing strings from 0 not 1, I hate it!

Tom

What’s wrong with ‘1’ based indexing ?
The ‘0’ based indexing à la C is a major source of bugs.

  1. If I need an array of 256 of anything. I can’t use one byte as an index.
  2. The offset to the 1st position in any array is 0 not 1.
  3. If you want to refer to the offset of a particular character in the array you have to add 1 all the time.
  4. It isn’t the way the system works.
  5. It is absolutely not a source of bugs though there are many things wrong with C string handling that is not one of them. I don’t think you have much experience in C in 30 years I have never seen that as a source of bugs, many other things but not that.

Tom

GNAT knows how to deal with a byte-size index with a range that doesn’t start at 0:

 1. procedure Indexing is
 2.    type Index is range 42 .. 42 + 255
 3.    with Size => 8;
            |
    >>> warning: size clause forces biased representation for "Index" [-gnatw.b]

 4.    type Arr is array (Index) of Character;
 5.    A : Arr := ('a', 'b', others => 'y');
 6. begin
 7.    pragma Assert (A (A'First) = 'b');
 8.    A (42) := '1';
 9.    pragma Assert (A (A'First) = '1');
10. end Indexing;

Why is it a problem ?

How do you iterate over to the range 0-255 with a byte ?
for (Index = 0; Index ??? ; Index++)
What should be ???

Who said that ?
0-based indexing is a computer invention.
Humans are used to 1-based indexing.

In C like (and many other) languages 0-based indexing is the rule. This is not the case in many other languages.
There is a list here showing 0-based, 1-based or n-based array indexing languages.

my_string : string := "This is my string";
“T” is my_string (1), there’s no offset to add (as the first character index is 1).

Which system ?
In C, you use raw types where the memory content is directly what your data structure describes and the compiler does no assumption on it (so it does not check anything).
In Ada, you use safe types where the compiler is free to map your data structure content to what it wants in memory. Ada arrays might store the array content and metadata (array bounds). This allows the compiler to add runtime checks.

It is a source of bugs. In 30 years, I’ve seen plenty of them.

For example when you want to access the 4rth array entry :
my_array(4) is the human way of thinking.
In C you have to write my_array[3] which is a computer way of thinking.
In C since you have to switch from human way of thinking to computer way of thinking all the time, you write bugs.

It depends. If the index represents an offset, 0-based is best. If it represents a position in a vector or a row or a column in a matrix, 1-based is best. In a 0-based language, either you waste the 0th colmn & row, or you have to do -1 everywhere (it is tedious and sometimes you forget about it…). Same for the position of a character: first character → 1.
Fixing everything at 0 or 1 is a mistake of most languages.

1 Like

…and sometimes it makes perfect sense to enumerate an array by an enumeration; i.e.,

-- not actual code; might not compile; but based on code I've written
type Direction is ( North, South, East, West );
dx: constant array ( Direction ) := ( 0, 0, 1, -1 );
dy: constant array ( Direction ) := ( 1, -1, 0, 0 );
subtype Rows is Integer range 0 .. 99;
subtype Cols is Integer range 0 .. 99;
data: array ( Rows, Cols ) of Integer := ( others => 0 );

begin

   -- some awesome setup happens here

   for i in Rows'First + 1 .. Rows'Last - 1 loop
      for j in Cols'First + 1 .. Cols'Last - 1 loop
         for dir in Direction loop
            -- for instance
            data ( i, j ) := data ( i + dx ( Direction ) , j + dy ( Direction ) );
         end loop;
      end loop;
   end loop;

end;

It’s one of my favorite Ada features, something no other active language I’m familiar with does so easily & naturally at the moment. I think Pascal and Modula-2 did it well, but they’re dead and IIRC Oberon dropped this feature. Rust really needs this feature.

2 Likes

Hi thanks for this interesting code but I still feel that I prefer not to start an index at 1 when really I mean an offset of 0. There are a lot of things we can do but usually if it’s not the way the processor does it, it leads to additional complexity for no reason. There is no rational argument in my mind to index from one when we are dealing with an offset. Thanks for the code though, even though it doesn’t convince me to change it is a reflection of Ada’s impressive capabilities.

Tom

Thanks for taking the time to argue soo many points.

  1. for (Index = 0; Index ??? ; Index++) Indeed you would have to test after the body of the loop and before the increment. In assembler of course you just check the overflow flag.
  2. “a computer invention”? Yes humans use 1 based indexing often e.g. 1900 is the first year of the 20th century. It’s a bit crap. When we measure an offset we start at 0 and always did. Yes when we count things we usually start at 1. 1 goat etc. But when indexing arrays we are offsetting not counting.
  3. Say I have a string stored in memory at 0A00 then the first character is 0A00+0 not 0A00+1. To make the first character at offset 1 I need to reduce the base by 1 i.e. 09FF but then 09FF is meaningless. It’s a mess. If I want to store multiple strings in one string as a concatination of strings there is considerable nonsense.
  4. “It isn’t the way the system works” I mean try to find me a processor where you use an index register and that index register starts at 1 not 0. I am very happy that Ada does many checks but I don’t think these benefit by starting from 1 while the underlying machine starts from 0.
  5. In 30 years of programming in Ada perhaps because you persist in this crazy way of indexing when as I have said an index is actually an offset not an index at all. A baby in it’s 1st year of life is 0 years old. Abandon your obsession with indexing, accept offsets and you will never see this confusion. I speak from experience, this is not a cause of bugs in C. Zero terminated strings are a cause bugs. Arrays without bounds checking on functions like strcat and that sort of thing yes for sure it is a mess. But the 0 start for a string is not.

OK I have no problem with the idea that a programmer can choose to index from say 342 to 784 it’s a nice feature but at the same time a string library where strings are indexed from 1 I hate. I am not sure where you get your -1 idea from unless your talking about the conversion from 1 based indexing to 0 based offsets. I never had to subtract 1 on the contrary I had to add one and got in quite a mess trying to implement a circular buffer with Ada. Yes I wasn’t so experienced then and haden’t written my own string handling stuff at that point.

OK I’m really not clear what you are trying to demonstrate here or why you want to start at First+1 and finish with Last-1 as it seems you are leaving a “frame” of uninitialised values around the edges of your “data” array. There is nothing wrong in my opinion of enumerating an array by an enumerator. I’s a feature I also like.

1900 is the first year of the 20th century

No, it is the last year of the 19th century.

I didn’t follow the discussion, but I like very much this quotation : :grinning:
“Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration.” (Stan Kelly-Bootle)

3 Likes