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

epilogue blandness at mygrave.net
Thu May 11 23:00:03 UTC 2023


On Thursday, 11 May 2023 at 00:56:03 UTC, ryuukk_ wrote:
> Don't you find this code easier to read and review?
>
> ```D
>         if (target.os == .Windows)
>         {
>             item("windows");
>         }
>         else
>         {
>             item("posix");
>             if (target.os == .linux)
>                 item("linux");
>             else if (target.os == .OSX)
>                 item("osx");
>             else if (target.os == .FreeBSD)
>             {
>                 item("freebsd");
>                 item("bsd");
>             }
>             else if (target.os == .OpenBSD)
>             {
>                 item("openbsd");
>                 item("bsd");
>             }
>             else if (target.os == .Solaris)
>             {
>                 item("solaris");
>                 item("bsd");
>             }
>         }
>         arrayEnd();
> ```

No, I find this harder to review.

`.` is the module scope operator, which is already going to be 
difficult for new dlang coders to learn about given that they 
would end up searching for the meaning of the `.` character (I 
speak from *my* experience learning D).

I haven't reviewed the DIP in full, but a quick search of the DIP 
for "module scope operator" does indicate that overloading the 
module scope operator was already called out as undesirable, so 
I'm not sure why you would use `.` again here when trying to 
defend the rejected DIP.

Having read the conversation, but not the DIP, I think the 
repetition issue is known, but the examples offered don't 
demonstrate (to me, a random nobody reading this thread) a clear 
improvement of the language or the code in question.

I will add that this particular case of repetition the DIP seems 
to be intended to solve reminds me of brace-expansion in bash, 
where `foo.iso{,.sig}` expands to `foo.iso foo.iso.sig` allowing 
bashers to avoid repetition in some cases of repetitive strings, 
but it should be evident to anyone subjected to reading someone 
else's bash script that that reducing repetition with brace 
expansion does not unconditionally improve reviewability of the 
code in question.



More information about the Digitalmars-d-announce mailing list