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

mw mingwu at gmail.com
Wed Oct 19 04:52:31 UTC 2022


Following the discussion from:
--------------------------------------------
https://forum.dlang.org/post/kyonizwffgvpuvrwhoog@forum.dlang.org

On Wednesday, 19 October 2022 at 01:49:26 UTC, mw wrote:
> On Wednesday, 19 October 2022 at 01:38:27 UTC, Adam D Ruppe 
> wrote:
>> On Wednesday, 19 October 2022 at 01:34:54 UTC, mw wrote:
>>> Is there any (design) doc about this?
>>
>> scroll up, click the link from this very thread.
>>
>> https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1038.md#design-goals-and-possible-alternatives
>
> """
> Rather than make either sacrifice, this DIP proposes a design 
> that allows both rigor and simplicity to be maintained, and 
> reserves the possibility for a future DIP to allow @mustUse as 
> a function attribute.
> """
>
> Another future DIP? I think this DIP is flawed for not using 
> "@mustUse as a function attribute"

@mustuse as a function attribute was in the original version of 
the DIP. It was vetoed by Walter. Thus, only the type attribute 
remains in the accepted version.

FWIW, this is the same path that #[must_use] took in Rust. It was 
added originally as a type attribute only, and later had its 
usage extended to functions.
--------------------------------------------


In case anyone does not know, I'd like to refer to the following: 
command query separation principle

https://en.wikipedia.org/wiki/Command%E2%80%93query_separation#:~:text=Command-query%20separation%20(CQS),the%20caller%2C%20but%20not%20

"""
It states that every method should either be a command that 
performs an action, or a query that returns data to the caller, 
but not both.
"""

For a query, its return value should never be disregarded, this 
is forced by the Eiffel compiler.

The kind of problem (wasting hours of development time, 
frustration and pain) the OP's author has experienced would have 
never happened if s/he is using Eiffel.


@Walter, you haven't study Eiffel well enough? although you said 
you have Meyer's book?




More information about the Digitalmars-d mailing list