Deprecating this(this)

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sun Apr 1 12:27:44 UTC 2018


On Sunday, April 01, 2018 11:37:21 Guillaume Piolat via Digitalmars-d wrote:
> On Sunday, 1 April 2018 at 01:01:24 UTC, Jonathan M Davis wrote:
> > So, I think that the only large-scale benefit thet exists for
> > pure and really can exist for pure is the fact that you know
> > that the function doesn't access global, mutable state.
> > Everything else it does is just gravy and too limited to be a
> > "large-scale" benefit. Certainly, optimizations are clearly
> > _not_ the main benefit of pure, since they almost don't exist.
> > But over time, we have managed to add more gravy here and there
> > as we've figured out assumptions that can be made based on pure
> > (like the case where we can convert the result of a pure
> > function to immutable).
> >
> > - Jonathan M Davis
>
> Great write-up.
>
> Why keep pure when the benefits obviously don't outweight the
> costs?
> Here is what I interpret reading this: "lost productivity".

Personally, I don't think that the costs outweigh the benefits. Yes, if your
primary goal is optimizations, then pure falls flat on its face, but
personally, I think that the fact that pure allows you to prove that a
function doesn't access any global, mutable state except through its
arguments is quite valuable. There are still some things in druntime and
Phobos which don't work with pure like they should, but in general, I
haven't found that it's really a big problem. Some code can't be pure, and
that's life, but a _lot_ can be. If anything, I find that const is the
attribute that causes problems, not pure.

But if you don't want to use pure, then don't use pure. Nothing is forcing
you to use it, and if someone else insists on making their code work with
pure, it's only a problem for you if they're trying to call your code, and
they complain about the fact that your code doesn't work with pure.
Certainly, code that isn't pure has no problems calling code that is, so if
other folks go to the effort of making their code work with pure, it won't
cause you problems.

- Jonathan M Davis



More information about the Digitalmars-d mailing list