Enum literals, good? bad? what do you think?

Dukc ajieskola at gmail.com
Thu Jul 22 19:37:36 UTC 2021


On Thursday, 22 July 2021 at 14:58:12 UTC, Paul Backus wrote:
>
> Ok, now imagine you're new to D and don't know about this 
> feature. What are you going to *think* `E e = ".y"` does?
>

There would be a risk that I'd think that it's the same as `E e = 
.y`. Not that likely though - I may well know that E has a member 
y, and I could also reason that `".y"` meaning `.y` would make no 
sense since one could just write `.y` directly.

I think you're worried about the case where I don't know that `E` 
is an enumerated type. In that case I could mistake `E` being 
some sort of string type. On the other hand, I could not fully 
trust that conclusion anyway, since it could also be some custom 
`struct` or `union` that can be initialized that way.

> Using string-literal syntax for things that aren't actually 
> string literals is just asking for confusion.

To some degree yes. But perhaps it's still better than new syntax.


More information about the Digitalmars-d mailing list