4 ms·
I like the "clean feel" of Ada's syntax: it combines the elegance of Python with a bit more structure and does not suffer from Python's significant whitespace
by thesuperbigfrog 6y ago
I like the "clean feel" of Ada's syntax: it combines the elegance of Python with a bit more structure and does not suffer from Python's significant whitespace issues.
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
-- local variables declared here
begin
-- program work here
exception
-- exception handling here
end Square_Root;
- linuxlizard 6y agoI did Ada back in university. I wrote a toy Ada compiler for my master's thesis. I was so enamored with Ada's exception handling at the time! When I discovered Python and its similar exception handling, I jumped onto Python in a heartbeat.
- OneWingedShark 6y agoAwesome, you wouldn't still have a copy of your Ada compiler's source do you?
- cafard 6y agoI use PL/SQL a fair bit, which was inspired by Ada. Unfortunately, the designers did not bring over ShortName is New ReallyLongAndAwkardName; Ah, well.
- OneWingedShark 6y ago> I use PL/SQL a fair bit, which was inspired by Ada. I have a bit of a project-idea here: PL/SQL+Ada+VHDL all together in an IDE. > 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.
- cafard 6y agoRENAME is a command in Oracle SQL. I see in the documentation that PL/SQL gives it as a "keyword", not as a "reserved word". This means, I gather that you can name a subprogram as RENAME, though Oracle recommends against it. You could not, on the other hand name a subprogram INSERT, unless you double-quoted it--which, again, Oracle recommends against.
- cneu 6y agoSome things are partially implemented: - 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.
- deleted 6y ago[deleted]
- wott 6y ago> 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. "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...
- Jtsummers 6y agoHN formatting tip: Put two extra spaces in front of each of those code blocks and remove all those unnecessary blank lines and you're comment will be tolerably formatted. As it is, it's a PITA to read because it spans several screens without any good cause.