Proposal: Relax rules for 'pure'
Don
nospam at nospam.com
Wed Sep 22 12:52:03 PDT 2010
Steven Schveighoffer wrote:
> On Wed, 22 Sep 2010 15:21:57 -0400, klickverbot <see at klickverbot.at> wrote:
>
>> On 9/22/10 9:14 PM, Steven Schveighoffer wrote:
>>> Hypothetical counter-case
>>>
>>> struct S
>>> {
>>> version(stronglypure)
>>> string s;
>>> else
>>> char[] s;
>>> }
>>>
>>> pure foo(S s); // changes strength depending on S' contents
>>>
>>> -Steve
>>
>> This is a change to the signature of foo – S with the stronglypure
>> version defined and S without it are two completely distinct types.
>
> Wait, I didn't change foo's signature at all. This is what the OP meant
> by long-range changes. S can be defined far away from foo, and out of
> the author of foo's control.
>
> -Steve
Is that really what he meant?
Note that foo() would need to be recompiled, and the silent change in
strength would occur only if it still compiles despite a significant
change in the definition of one of types.
If you change the definition of a type, you're always going to have
influences everywhere it's used in a function definition. I'd hardly
call that a 'long-range' change.
By contrast, in a language where you don't have pure at all, if someone
sticks in a global variable somewhere, (even in a separate library),
then code could suddenly have severe contention with another thread.
That's long range, and nearly impossible to track down.
More information about the Digitalmars-d
mailing list