News for hackers. Stuff that matters.
Re:Giving Ada a Chance by thesuperbigfrog on Monday March 01, 2021 @11:23AM (#26304336)
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;
Re:Giving Ada a Chance by linuxlizard on Tuesday March 02, 2021 @11:56AM (#26317366)
I 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.
Re:Giving Ada a Chance by OneWingedShark on Tuesday March 02, 2021 @05:26PM (#26321935)
Awesome, you wouldn't still have a copy of your Ada compiler's source do you?
Re:Giving Ada a Chance by cafard on Tuesday March 02, 2021 @02:43PM (#26319561)
I use PL/SQL a fair bit, which was inspired by Ada. Unfortunately, the designers did not bring over

ShortName is New ReallyLongAndAwkardName;

Ah, well.

Re:Giving Ada a Chance by OneWingedShark on Tuesday March 02, 2021 @05:36PM (#26322056)
> 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.

Re:Giving Ada a Chance by cafard on Wednesday March 03, 2021 @09:10AM (#26328473)
RENAME 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.
Re:Giving Ada a Chance by cneu on Wednesday March 03, 2021 @09:05AM (#26328415)
Some 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.
Re:Giving Ada a Chance by wott on Tuesday March 02, 2021 @05:22PM (#26321876)
> 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...

Re:Giving Ada a Chance by MarcusE1W on Wednesday March 03, 2021 @06:40AM (#26327138)
I think everything you say is explained correctly, just that you describe a very special fringe case. The variables in your `declare` block only need to exit during the if, so this is one way to manage their lifespan.

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.

Re:Giving Ada a Chance by Jtsummers on Tuesday March 02, 2021 @05:48PM (#26322202)
HN 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.
Re:Giving Ada a Chance by tenken on Tuesday March 02, 2021 @10:32PM (#26324402)
These seem contrived. Ada supports encapsulation, at the procedure or package level. I would just declare up-front the A,B,C,D variables .... I don't see what the begin/end blocks buy you kn these examples.