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 Bare 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!
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;
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. ...
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.
Randy.
P.S. Man. did I spend a lot more time than I planned answering this. I hope it helps.
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, butI 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!
I often find myself writing a loop to search ...
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?
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;
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...
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 71:59:32 |
Calls: | 8,084 |
Calls today: | 2 |
Files: | 13,069 |
Messages: | 5,849,955 |