Entomy / Ada-Improvements

Repository of Ada language improvement ideas
GNU General Public License v3.0
4 stars 0 forks source link

Variable declaration #9

Open Entomy opened 5 years ago

Entomy commented 5 years ago

Ada does:

I : Integer := 1;

It should be:

variable I : Integer := 1;

Rationale: This proposal is twofold:

  1. This enables the more orthogonal design of introducing everything with the keyword of what's being introduced.

  2. It's better for the parser as we have a clear introduction instead of repeatedly guessing why an identifier is at the start of a statement.

While variable is used, var would be fine. I'm optimizing for syntax because intellisense greatly reduces keystrokes regardless.

Joebeazelman commented 2 years ago

If I'm correct, Ada uses declare as the formal way to declare variables, but it's rarely used except to create local scope for temporary variables similar to {...} in C#.

Ada didn't borrow Pascal's var block which IS required:

Var  
  Origin : Point = (X:0.0; Y:0.0);  
  Partial : Point = (X:0.0);  
  Empty : Point = ();

Using declare instead of var makes it clear the subsequent statements declare more than just variables. Are arguing it should be required.

Entomy commented 1 year ago

@Joebeazelman Whether variables would be declared within a block or not would be its own issue to contend. If this proposed option were to go forward, it would assume no declaration blocks. If declaration blocks are kept, this would be redundant.