DIPX: Enum Literals / Implicit Selector Expression
ryuukk_
ryuukk.dev at gmail.com
Thu Jun 30 20:32:49 UTC 2022
On Thursday, 30 June 2022 at 17:15:46 UTC, ShadoLight wrote:
> On Thursday, 30 June 2022 at 11:32:42 UTC, ryuukk_ wrote:
>
>> ```
>> 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?
>
> Where do you want to use it where it cannot be used?
>
> This works today:
>
> ```
> with(Color)
> final switch(color) {
> case red: writeln("red"); break;
> case orange: writeln("orange");
> }
> ```
>
>
> ```
> with(MySuperLongName) set_my_flag( MyFlagA | MyFlagB |
> MyFlagC | MyFlagD | MyFlagE | MyFlagF);
> ```
> More clear at the cost of a few more characters to type. Quite
> acceptable compromise in my view.
Now it is harder to see the function, 'with' is nice when you
need to pull in a symbol into a scope
It is not nice when you just want to call a function with your
enum
Other languages who have it didn't go with a 'with' for a reason,
it adds unecessary noise
You don't do:
with(int) set_my_int(5 + 6 + 7 + 8 + 9 +10);
It kills the intent to make things simpler and logical, functions
expect Enum, we give its value
Function expect int? we give a value
More information about the Digitalmars-d
mailing list