comp.lang.ada
 help / color / mirror / Atom feed
* Ada needs some modernization
@ 2022-05-31 17:54 Matt Borchers
  2022-05-31 19:05 ` Gautier write-only address
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Matt Borchers @ 2022-05-31 17:54 UTC (permalink / raw)


Throughout my career, I often find myself writing code similar to:

if (A and B) or else (not A and C) then...

and I always wished there was a better and clearer way to write this in Ada.  Then along came if expressions.  But, if expressions don't help that much with readablity although it is arguably simpler:

if (if A then B else C) then...

What amendment can we suggest to the Ada syntax so the if expression be better written when used in an if statement?  I know other languages support this and it often looks like  A ? B : C  or something similar.  That's certainly not Ada-like IMO, but I can't think of something better. These same languages often also have a null check operator  A ?? B  (where A and B are access types of the the same Type) such that if A is not null then A is returned otherwise B is returned.  So useful and helpful!

-----

Again, I often find myself writing a loop to search for something and then performing one or another action depending on the success of the search.  This almost always requires some externally defined variable, like:

--assuming arr'First is not Integer'First
found := arr'First - 1;
for i in arr'Range loop
    if arr(i) = match then
        found := i;
        exit;
    end if;
end loop;
if found in arr'Range then
    --do something A
else
    --do something else B
end if;

Of course I could more the "do something A" into the if block within the loop, but I still need to know if I must run the alternate code afterward.  It would be nice to avoid having to create a variable just to indicate the success state or indexing location found.  Maybe something like:

for i in arr'Range loop
    if arr(i) = match then
        --do something A
        exit;
    end if;
then
    --do something else B
end loop;

The "then" part only executes after the loop terminates normally, i.e. only when the loop does NOT exit early by "exit" or "return" statement.

I think syntax enhancements like these could go a long way to making Ada feel like it is at least keeping up with modern languages and I think current programmers expect "ease-of-use" syntax from today's languages.  Other contemporary modernized languages have taken ideas from Ada, but Ada has not continued to pioneer ideas as quickly.  Perhaps that's by choice or design.

Thoughts?

Regards,
Matt

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-10 16:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 17:54 Ada needs some modernization Matt Borchers
2022-05-31 19:05 ` Gautier write-only address
2022-05-31 19:55 ` Dmitry A. Kazakov
2022-05-31 22:46 ` Randy Brukardt
2022-06-01  7:24   ` John McCabe
2022-06-01 19:00 ` Jeffrey R.Carter
2022-06-02  5:56 ` G.B.
2022-06-10 16:38 ` Brad Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox