Discussion Thread: DIP 1044--Enum Type Inference--Community Review Round 1

IGotD- nise at nise.com
Tue Nov 22 11:10:58 UTC 2022


On Tuesday, 22 November 2022 at 09:37:43 UTC, bauss wrote:
>
> If it's not implemented with .identifier then I will oppose it.
>
> I don't buy the "it will break code" point of view either.
>
> The only thing I can think of that will break is that 
> .identifier already has a meaning today that means module scope.
>
> But that could easily mean module AND "static/scoped" lookup 
> and any ambiguity can be fixed by prioritization.
>
> 1. module scope 2. enum 3. static members of ex. classes
>
> So if you type .a then it will first look in module scope, then 
> in enums that are in scope and at last within classes that are 
> in scope.
>
> I suggested something like it earlier too.
>
> Anything that is more complicated than .identifier is not worth 
> it and will only introduce unncessary complexity to the 
> language syntax.
>
> Example:
>
> ```d
> class A { static int a = 1; static int b = 2; }
> enum B { b = 3, c = 4 }
> int c = 5;
>
> void main() {
>   writeln(.a);
>   writeln(.b);
>   writeln(.c);
> }
> ```
>
> Prints:
>
> 1
> 3
> 5

I agree with this. In general the D project has become "don't 
break my beautiful parser/lexer" rather than what languages are 
supposed to do which is helping humans create/read code.

Another thing is that globals are in general sparse so that there 
will likely not be an ambiguity between enums and globals. There 
is a higher likely hood that there will be a ambiguity between 
locals/members and enums with the syntax without the '.'.

The . syntax is used in several other languages which helps and 
also it also helps the programmer understanding that it is an 
enum and not variable of any kind.



More information about the Digitalmars-d mailing list