Date: Sun, 16 Feb 2025 12:54:28 +0100
On sön 2025-02-16 at 12:08, Tiago Freire via Std-Proposals wrote:
> If you are going to do that, perhaps we can simplify the syntax a little
> bit.
>
> Instead of having to declare [mutable const] which makes the variable
> open for writes like any other regular variable.
>
> We could just omit [mutable const] and deduce that after the fact
> depending on either or not a close statement is used, instead of:
>
> [mutable const] int x = 0;
>
> const x;
>
> you would simplify it as:
>
> int x = 0;
>
> const x;
>
The two-step declaration has the disadvantage that it invites typos. Or
when you change the name of x, you might forget the const declaration
half a page further down. Now some other x is const?
This reminds me of a similar problems with goto, where added code before
and after the label affects what the goto means (in a totally different
location).
> If you are going to do that, perhaps we can simplify the syntax a little
> bit.
>
> Instead of having to declare [mutable const] which makes the variable
> open for writes like any other regular variable.
>
> We could just omit [mutable const] and deduce that after the fact
> depending on either or not a close statement is used, instead of:
>
> [mutable const] int x = 0;
>
> const x;
>
> you would simplify it as:
>
> int x = 0;
>
> const x;
>
The two-step declaration has the disadvantage that it invites typos. Or
when you change the name of x, you might forget the const declaration
half a page further down. Now some other x is const?
This reminds me of a similar problems with goto, where added code before
and after the label affects what the goto means (in a totally different
location).
Received on 2025-02-16 11:54:39