[phobos] Pureness of enforce()
Andrei Alexandrescu
andrei at erdani.com
Fri Nov 12 10:58:08 PST 2010
On 11/12/10 10:21 AM, Steve Schveighoffer wrote:
>
>
>
>
> ----- 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...
The former. I consider the latter a correctable QoI issue.
> 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
To which I replied that I doubt usage inside Phobos is representative.
Good runtime error messages have been a low (== 0) priority to Phobos.
In application code I almost always need to construct a string with text().
> 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.
Now that would be interesting. By and large, I'd be okay with being able
to overload on purity.
Andrei
More information about the phobos
mailing list