Command–query separation principle [re: @mustuse as a function attribute]
mw
mingwu at gmail.com
Sat Oct 22 17:47:07 UTC 2022
On Wednesday, 19 October 2022 at 21:13:00 UTC, mw wrote:
> On Wednesday, 19 October 2022 at 13:17:00 UTC, Paul Backus
> wrote:
>>
>> In other words, you cannot introduce `@mustuse` in a derived
>> class; it must be present in the base class.
>>
I spent some more time thinking about this, and I do not agree
with this rule even though I know what your design goals (and
constraints) are.
I will make an improved proposal based on my initial transitive
closure design, and I will write a longer post about it, which
may take some time, please bear with me.
As a summary, this is what I am going to propose: introduce two
variants of @mustuse
1) @mustUse_remedyLegacy: this annotation is to allow programmer
flag existing legacy library code that s/he has no right to
change, but want to set a flag and let the compiler to help to
find violations, but the compiler only output warnings instead of
errors.
2) @mustuse: proper, the default. For programmer to use in new
code, or library code s/he can change (from the root of the
inheritance tree). Violations of this annotation will cause
compiler error.
And:
a) in both cases, this function property will be transitive
closure, I.e. be propagated upwards and downwards, in all
directions.
b) in both cases, removing the annotation is *not* allowed in the
derived class if the supper class method carry such annotation.
I will write more about my rationale and considerations, and give
examples when I get more time.
More information about the Digitalmars-d
mailing list