Simplification of @trusted
Walter Bright
newshound2 at digitalmars.com
Thu Jun 17 18:25:44 UTC 2021
On 6/17/2021 8:59 AM, H. S. Teoh wrote:
> What are the actual advantages of code being marked pure? I'm all for
> generalizing pure, but does it bring enough actual benefits to be worth
> the effort?
>
> I'm not talking about theoretical benefits, but actual benefits that the
> compiler can actually make use of to emit better code. I used to be a
> big fan of pure, but in practice I've found that it doesn't make *that*
> much of a difference in terms of codegen. Maybe I'm missing something,
> in which case I'd love to be enlightened.
You're right it doesn't make that much difference in code quality. What it
*does* provide is:
1. makes it easy to reason about
2. makes unit testing easy
Just think about trying to unit test a function that side-loads various globals.
More information about the Digitalmars-d
mailing list