ShortName is New ReallyLongAndAwkardName;
Ah, well.
> Unfortunately, the designers did not bring over > ShortName is New ReallyLongAndAwkardName; Do you mean renames? Package Text renames Ada.Strings.Fixed;
IIRC, RENAME is in the keywords list for PL/SQL.
- type BOOLEAN is (FALSE, TRUE);
- type VARCHAR2 is NEW CHAR_BASE;
- generic collections
- varargs
Unfortunately, they are only available for the PL/SQL team itself."Declare" blocks are a PITA. I don't mean the declaration part in the subprogram example you quoted (that's fine), but having to use explicit "declare" blocks to create new variables in the scope of a loop or a conditional. You can't just declare variables after the introducing keyword (then, loop, ...), possibly between it and a "begin" that would be fused to be come a part of the loop/conditional syntax. You have to use a separate "declare" block, with its "begin" and its own "end;", and then you still have to have the "end loop;"/"end if;" of the loop/conditional itself.
Illustration.
A normal conditional:
---------
if A = 5 then
B := 7;
C := A + 1;
end if;---------
What you'd think you could at least do (it would already be a bit heavy, but by Ada standard verbosity it would be a good and smooth fit):
---------
if A = 5 then
declare
D : natural;
begin B := 7;
D := 1;
C := A + D;
end if;---------
What you actually need to do:
---------
if A = 5 then
declare
D : natural;
begin
B := 7;
D := 1;
C := A + D;
end;
end if;---------
So you waste one indentation level more each time you add one such declare block. Talking about combs, this get hairy quickly even when you have simply a few nested loops/conditionals.
Also, the "end;" of the "declare" block is not an "end declare;" or "end block;" like you have "end if;" and "end loop;". So that make it a bit harder again to know where you are when you are closing your blocks/loops/conditional.
Then you can add a label, but that make it even heavier (and good luck finding a clever name for the block label each time). Not sure there exists a good solution to place the (opening) label. And the closing label comes at the same place a closing keyword, which may be considered a bit confusing.
---------
if A = 5 then
myblock:
declare
D : natural;
begin
B := 7;
D := 1;
C := A + D;
end myblock;
end if;---------
or
---------
if A = 5 then
myblock: declare
D : natural;
begin
B := 7;
D := 1;
C := A + D;
end myblock;
end if;---------
or
---------
if A = 5 then
myblock:
declare
D : natural;
begin
B := 7;
D := 1;
C := A + D;
end myblock;
end if;---------
The last one, which wastes not only 1, but 2 indentations levels(!), and even worse, creates an indentation gap in the end, happens to be the recommended style...
In Ada as in almost every language you are well advised to have small functions with limited scope and then build on top of them. This would mean if you would declare your variables as normal part of a function the variables would have the lifespan of the function, and the function being small and to the point would also not be that long and you can avoid all the additional effort with `declare`.
I am not saying that there is no use for `declare` but it’s not needed that often or a big hassle in my view.
Ada is a bit more verbose than other languages and has one of the main aims to be readable on the basis that you write it once and read it many times.
The so-called "Ada comb" structure that is used for packages, subprograms, and even declare blocks makes it easy to find what you are looking for because it makes the source code more regular.
The "Ada comb" is formed by the shape of the source code with the subprogram header / declare, begin, exception, and end forming the "teeth" of the comb and the rest of the source code indented between the "teeth":
function Square_Root (Arg : Float) return Float is
begin exception end Square_Root;