DIP1044---"Enum Type Inference"---Formal Assessment

ryuukk_ ryuukk.dev at gmail.com
Mon May 1 00:34:03 UTC 2023


On Thursday, 27 April 2023 at 13:03:17 UTC, bachmeier wrote:
> On Thursday, 27 April 2023 at 06:10:57 UTC, Basile B. wrote:
>> On Thursday, 27 April 2023 at 00:16:10 UTC, Walter Bright 
>> wrote:
>>> This also works:
>>>
>>>     alias F = MySuperLongNameFlag;
>>>
>>>     auto flag = F.A | F.B | F.C | F.D;
>>>     set_flags(F.A | F.B | F.C | F.D);
>>>
>>> It's similar to setting a local variable to some complex 
>>> expression, just so you don't have to repeat that expression 
>>> multiple times.
>>
>> It's a misconception of the problem that the DIP tried to 
>> solve. What the DIP tried to solve is that the compiler should 
>> know that you are using an enum member. Actually I even think 
>> this should work without any special syntax, as a "last 
>> resort", let's say. But as you've explained, through Mike's 
>> report, this causes problems for D because the identifier 
>> resolution is tied to a particular implementation, i.e your 
>> fast symtabs.
>
> I don't think it's a misconception. It's more like a complete 
> lack of clarity. What would be the point of complexifying the 
> language for the new programmer when you can just use an 
> anonymous enum? This program runs just fine:
>
> ```
> import std.stdio;
>
> enum {
> 	A1,
> 	B1,
> 	C1,
> 	D1
> }
>
> enum {
> 	_A,
> 	_B,
> 	_C,
> 	_D
> }
>
> void main() {
> 	writeln(A1);
> 	writeln(_A);
> 	writeln(A1 == _A);
> 	
> 	auto flag = _B;
> 	switch(flag) {
> 		case _A:
> 			writeln("_A");
> 			break;
> 		case _B:
> 			writeln("_B");
> 			break;
> 		case _C:
> 			writeln("_C");
> 			break;
> 		case _D:
> 			writeln("_D");
> 			break;
> 		default:
> 			break;
> 	}
> }
> ```
>
> What's the point in using a named enum if you want an anonymous 
> enum? The response when this question was asked was not 
> "because [something where it matters]". It was instead to 
> ignore the question, give an unrealistic example that was 
> solved by the response, and insert a bunch of unhelpful 
> hostility.

what's the point? if you read the discussion that happened for 
the DIP you wouldn't ask the question

the goal is not to use an anonymous enum, the goal is to leverage 
the robust type system to avoid repeting yourself, wich is bad

```
Value value;
value.type = ValueType.STRING;
```

vs

```
Value value;
value.type = .STRING;
```

Read your code, would you read a book where each sentence would 
be a repetition of the previous one?

"Billy went to the town to buy some beer, as he arrived to the 
town to buy some beer he met Richard, as he arrived to the town 
to buy some beer Richard, that he just met, asked him how his 
wife was doing"



More information about the Digitalmars-d-announce mailing list