Interface Limitations in D
Steven Schveighoffer
schveiguy at gmail.com
Mon Sep 20 13:35:35 UTC 2021
On 9/19/21 4:00 PM, Elmar wrote:
> * **`interface`s don't permit runtime constants.**
>
> Not limiting, only weird. Constants are stronly-pure niladic
> (no-arguments) functions and D syntactically doesn't differentiate
> between zero-argument function calls and variable accesses. I could
> define a static niladic function with constant return value in an
> `interface`. But the constant-member-syntax
> ```D
> static immutable myVar = 0;
> ```
> is easier to write.
>
> Constants are no state. The purpose of an interface is to
> describe API which is not supposed to change at runtime or during
> software evolution while not fixing behaviour and ideally not fixing
> future additions.
Not sure what you are saying here.
this code is valid:
```d
interface I
{
static immutable myVar = 0;
}
```
-Steve
More information about the Digitalmars-d
mailing list