Discussion Thread: DIP 1038-- at nodiscard--Final Review
maxhaton at gmail.com
Thu Feb 4 21:25:26 UTC 2021
On Thursday, 4 February 2021 at 20:15:07 UTC, Q. Schroll wrote:
> On Wednesday, 3 February 2021 at 11:25:29 UTC, Mike Parker
>> This is the discussion thread for the Final Review of DIP
>> 1038, "@nodiscard":
> I wonder how many non-void functions exist whose return values
> are usually ignored. The DIP correctly identifies the results
> of assignments as commonly discarded values. Apart from those,
> printf and readf come to my mind. All in all, I do think those
> functions are rare.
> Having an attribute for the common case seems backwards to me.
> More often than not, it will be omitted. It is probably better
> to do it the other way around: Add a @discard (or @maydiscard
> or @discardable) attribute to apply to printf, readf, and
> friends to indicate that discarding their result is an intended
> form of their use.
Doing dataflow analysis on every single function call would
probably be slow.
This DIP solves a specific problem - it's effectively (an
approximation) of a linear type system - there are certain
non-trivial types that must be consumed for the program to be
correct in some non-trivial way: Extending this logic to *all*
functions, e.g. ones returning integers may not be as fruitful as
you say, as we often have these return values to maintain the
flexibility of code rather than to enable a specific pattern, by
requiring everything to be annotated with some negative form of
this attribute is not ideal in many circumstances.
If you want to show that it is the common case, you have to show
that it is the common case.
More information about the Digitalmars-d