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

ryuukk_ ryuukk.dev at gmail.com
Sat Nov 19 03:22:30 UTC 2022


On Saturday, 19 November 2022 at 02:57:27 UTC, Walter Bright 
wrote:
> On 11/18/2022 6:06 PM, ryuukk_ wrote:
>> MySuperLongType flag = MySuperLongType.ValueA | 
>> MySuperLongType.ValueB | MySuperLongType.ValueC | 
>> MySuperLongType.ValueD | MySuperLongType.ValueE | 
>> MySuperLongType.ValueF | MySuperLongType.ValueG;
>> 
>> // vs
>> 
>> MySuperLongType flag = .ValueA | .ValueB | .ValueC | .ValueD | 
>> .ValueE | .ValueF | .ValueG;
>
> with (MySuperLongType)
> MySuperLongType flag = ValueA | ValueB | ValueC | ValueD | 
> ValueE | ValueF | ValueG;


Why should i have to type the name of the type twice? it doesn't 
help with readability


Imagine on this small example, that would be overkill

Little experiment, read it out loud, the repetition and noise is 
clearly not wanted

```D
NetworkState network_state = NetworkSate.DISCONNECTED;
```


Another example:

```D
if (client.network_state == NetworkState.CONNECTED)
     client.network_state = NetworkState.DISCONNECTED;

// vs

with (NetworkState)
if (client.network_state == CONNECTED)
     client.network_state = DISCONNECTED;

// same issue as above, reading it feels repetitive, and it adds 
extra cognitive load


// there, straith to the point
// you can name your variable more verbosely, you no longer have 
to duplicate enum type everywhere
// type system is smart enough
if (client.network_state == .CONNECTED)
     client.network_state = .DISCONNECTED;

```

Taken from my project, c'mon, if i use proper naming in my code, 
i should be allowed to ommit the typename of the enum

Just like i can omit the type of the integer
```D
int myInt = 42;

// and not
int myInt = int.42;
```

```D
     if (ctx.engine.input.is_key_just_pressed(.PAGE_UP))
     {
         cam_pos_d *= 1.2;
         cam_pos_h *= 1.2;
     }
```



More information about the Digitalmars-d mailing list