Command–query separation principle [re: @mustuse as a function attribute]

mw mingwu at gmail.com
Wed Oct 19 18:38:55 UTC 2022


On Wednesday, 19 October 2022 at 18:25:54 UTC, Paul Backus wrote:
> On Wednesday, 19 October 2022 at 18:16:39 UTC, mw wrote:
>> Yes, I know that. But this in my view is still a compiler 
>> implementation issue: even in separate dub packages, as long 
>> as the compiler visit that package, it need to propagate the 
>> attribute to that package's relevant class.
>
> My point is that, even if we assume it is possible to 
> implement, it is still a bad idea, because it would introduce 
> implicit coupling between modules where no coupling (explicit 
> or implicit) previously existed.

That's because now we want to add @mustuse half-way, and it 
requires global system analysis. If D started from scratch as 
Eiffel did, and enforces all query methods are @mustuse from the 
very beginning, such problem and remedy headache would never 
existed.

So now we need to balance either we want prevent accidentally 
(but fatal in most cases) discarding function returns, or we want 
prevent more coupling between modules.

For me, in this particular situation, I prefer the former which I 
think will make the code more robust.




More information about the Digitalmars-d mailing list