static if enhancement

Uranuz via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 25 07:17:02 PDT 2016


On Saturday, 25 June 2016 at 10:19:47 UTC, Claude wrote:
> On Friday, 24 June 2016 at 15:24:48 UTC, Andrei Alexandrescu 
> wrote:
>> Does anyone else find this annoying? 
>> https://issues.dlang.org/show_bug.cgi?id=16201 -- Andrei
>
> My 2 cents. I don't find that annoying at all. It's perfectly 
> normal IMHO.
>
> It may introduce an additional indentation level for the second 
> part, but I reckon it is normal to have those 2 instruction 
> blocks at the same level. If we were to introduce a new keyword 
> for "static if else", why not do the same for the run-time "if 
> else" (to be coherent)?
>
> And, if some code have too many indentation levels, than it 
> probably means it should be better modularized, hence I'd 
> suggest to split it in several sub-functions, it will be more 
> readable/maintainable.

I think if we want we could also add `if else` for run-time if 
too. In D we have wide usage of CT features and particularly 
`static if`. It becomes annoying and too verbose to write `else 
static if` when I have multiple branches, so I was thinking for 
some time to have `elif` keyword. In this case it would be enough 
to write static just one time at the beginning of `static if`. 
Compiler could understand that `elif` belongs to this exact `if` 
or `static if` that was before it.


More information about the Digitalmars-d mailing list