Discussion Thread: DIP 1044--Enum Type Inference--Community Review Round 1
ryuukk_
ryuukk.dev at gmail.com
Wed Nov 23 15:21:07 UTC 2022
On Wednesday, 23 November 2022 at 14:21:23 UTC, deadalnix wrote:
> On Wednesday, 23 November 2022 at 13:41:12 UTC, ryuukk_ wrote:
>> ```D
>> // verbose API, readable
>> struct SuperLongStruct
>> {
>> struct SuperLongInnerStruct
>> {
>> enum SuperLongEnum
>> {
>> VALUE_A, VALUE_B
>> }
>>
>> SuperLongEnum super_long_flags;
>> }
>> SuperLongInnerStruct some_data;
>> }
>>
>> // oh shoot
>>
>> SuperLongStruct super_long_struct = {
>> some_data: {
>> super_long_flags:
>> SuperLongStruct.SuperLongInnerStruct.SuperLongEnum.VALUE_A |
>> SuperLongStruct.SuperLongInnerStruct.SuperLongEnum.VALUE_A
>> }
>> };
>>
>> // oh nice!
>>
>> SuperLongStruct super_long_struct = {
>> some_data: {
>> super_long_flags: .VALUE_A | .VALUE_A
>> }
>> };
>>
>> ```
>
> Try `alias E =
> SuperLongStruct.SuperLongInnerStruct.SuperLongEnum;`
>
>
>> ```D
>> AttackType attack_type = .MELEE;
>>
>>
>> (..)
>>
>>
>> switch (attack_type)
>> {
>> case .MELEE:
>> break;
>> }
>>
>>
>>
>> ```
>>
>> now your variable name carry more and proper information about
>> what it is,
>
> ```d
> auto attack_type = AttackType.MELEE;
>
> switch (attack_type) with(AttackType) {
> case MELEE:
> break;
> }
> ```
```D
struct Action
{
AttackType attack_type;
}
// no auto here
```
in your switch, did you read it?
switch attack_type with AttackType
this is not appealing and is the noise and repetition that needs
to be suppressed
i was verbose when i declared my variable name, that's enough
and you didn't read my other comment
why should i declare an alias? it leaks the symbol to the scope,
it is another symbol that i need to remember when i refactor, and
it adds cognitive load when i read my whole module, too much
gymnastic and scope bloat
More information about the Digitalmars-d
mailing list