Worst ideas/features in programming languages?
russhy
russhy at gmail.com
Mon Nov 15 17:25:35 UTC 2021
On Sunday, 14 November 2021 at 18:41:10 UTC, Dr Machine Code
wrote:
> On Monday, 11 October 2021 at 18:27:29 UTC, russhy wrote:
>
> [...]
>
>>> Features you'd like to see in D
>>
>> - tagged union (built in, not as std/lib)
>> - interface / signature for structs (built in, not as
>> std/lib)
>> - alternatively, reintroduce the * for classes
>> - enum literals (being able to omit the enum name)
>> ex:
>> ```d
>> enum MyEnum { A, B, C}
>> MyEnum e = :A;
>> my_function(:A);
>> switch (e)
>> {
>> case :A: break;
>> }
>> // could be :, ., $, ! but that is not the point
>> '''
>
> This unscoped enums is one of the worst features in C/C++,
> imho. I loved when I switch to languages that the enum got its
> scopre but D you got both, you can also do:
>
> ```D
> enum A = 0;
> enum B = 1;
> // ...
> ```
>
> if you dislike to set their initial values manually, I think
> you can write a template function to create enum values
It's not unscoped, it type checked, it just removes the need to
be verbose and repetitive
```D
MyAbility ability;
switch (ability)
{
case MyAbility.SOMETHING_1: break;
case MyAbility.SOMETHING_2: break;
case MyAbility.SOMETHING_3: break;
case MyAbility.SOMETHING_4: break;
case MyAbility.SOMETHING_5: break;
}
```
What this repetition solves?
```D
void use_ability(MyAbility ability){}
use_ability(MyAbility.SOMETHING_1);
```
Imagine if you had to prefix the type of everything
```D
void use_my_int(int a) {}
use_my_int(int.4545846846);
```
Compiler can be smarter
Languages that allow removing the prefix for enums are popular it
helps a lot with readability
More information about the Digitalmars-d
mailing list