[phobos] Pureness of enforce()

Steve Schveighoffer schveiguy at yahoo.com
Fri Nov 12 10:21:04 PST 2010





----- Original Message ----
> From: Andrei Alexandrescu <andrei at erdani.com>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> Sent: Fri, November 12, 2010 12:17:15 PM
> Subject: Re: [phobos] Pureness of enforce()
> 
> We should leave enforce() as is and defining eagerEnforce() or 
> pureEnforce().
> 
> 1. No backwards-incompatible change
> 
> 2.  enforce() continues to mimic assert()'s behavior wrt its second  argument
> 
> 3. I'm not sure there will more pure functions than impure out  there. If 
> there are more impure functions, using enforce() becomes a net  pessimization
> 
> If we make the change, I see "Effective D" item #35:  "Beware of 
> enforce()'s inefficiency".

It's difficult to tell what you mean here by inefficiency -- inefficiency of 
eager version of enforce because the argument is pre-evaluated, or inefficiency 
of lazy version because it cannot be inlined...

In any case, here is the message I wrote about it: 
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=115131


I'd say enforce should be the common case, and the common case is that you are 
using constant-folded strings as the argument to enforce.

This almost begs for an 'auto lazy' feature.

-Steve



      


More information about the phobos mailing list