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

ryuukk_ ryuukk.dev at gmail.com
Sat Nov 19 03:31:50 UTC 2022


On Saturday, 19 November 2022 at 03:15:26 UTC, bachmeier wrote:
> On Saturday, 19 November 2022 at 02:06:57 UTC, ryuukk_ wrote:
>>
>> ```D
>> 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;
>> ```
>
> Very, very simple solution:
>
> ```
> MySuperLongType flag = M.ValueA | M.ValueB | M.ValueC | 
> M.ValueD |  M.ValueE | M.ValueF | M.ValueG;
> ```
>
> I mean, if you don't want to type that much, use shorter names.

Using shorter type/variable name is what hurts readability of 
your code

Using proper naming is the key, if i can omit the type name of 
the enum and leverage the type system, i am encouraged to use 
meaningful and longer type/variable name, wich improve readability

```D
// the function name is verbose, i know it passes the enumeration 
type of keys
is_key_pressed(.A);
is_key_pressed(Key.A);

// vs

// the function name is short, what should i pass?
// of you passed and enumeration type of keys
// therefore you ask if it's a key that was pressed
is_pressed(.A);
is_pressed(Key.A);

```

I should have the choice


More information about the Digitalmars-d mailing list