DIPX: Enum Literals / Implicit Selector Expression

bauss jj_1337 at live.dk
Thu Jun 30 11:34:02 UTC 2022


On Thursday, 30 June 2022 at 11:32:42 UTC, ryuukk_ wrote:
>> Not saying I'm against the feature, I just don't understand 
>> why `auto color = Color.orange` is a problem and how `Color 
>> color = .orange` is better. Because of four fewer characters?
>
> Indeed, this example doesn't make much sense, but the ony i 
> posted on the github shows exactly why we need it
>
>
> ```
> set_my_flag( MySuperLongName.MyFlagA |  MySuperLongName.MyFlagB 
> | MySuperLongName.MyFlagC | MySuperLongName.MyFlagD | 
> MySuperLongName.MyFlagE | MySuperLongName.MyFlagF );
> ```
>
> vs
>
> ```
> set_my_flag( .MyFlagA |  .MyFlagB | .MyFlagC | .MyFlagD | 
> .MyFlagE | .MyFlagF );
> ```
>
> One could argue to use ``with``
>
> But what about places where it can't be used? and it is counter 
> productive, if the goal is to remove repetition, why introduce 
> more?
>
> It already is explicit, and checked with the type system
>
> I suggest trying languages that have that feature and see how 
> practical, and just better enums feel to use
>
> I see myself still relying on constants to emulate enums...  in 
> D, because of that, that's not good

Meh... if you need to specify that many enum values then perhaps 
you just need a new field with all those values.


More information about the Digitalmars-d mailing list