On Wednesday, September 22, 2010 14:19:42 Steven Schveighoffer wrote:
> I just thought of something -- we may be defining the common case.  For
> example, D breaks from the default of shared globals in C because most of
> the time, variables *aren't* shared.  When I first heard of shared, I
> thought surely Walter was losing his mind.  Why would shared not be the
> default, clearly as it's done in C!  But after having used the language, I
> see that it would have been a huge issue if I had to mark everything as
> unshared.
> 
> If we can define weakly pure functions this way, they most likely will be
> way more common than unpure functions.  I know I avoid accessing global
> variables in most of my functions.  Think about a range, almost all the
> methods in a range can be weakly pure.  So that means you need to mark
> every function as pure.
> 
> Would it not be less tedious to mark unpure functions instead of pure
> functions?  Or am I just going too far with this?
> 
> OR, maybe we could say, mark strongly pure functions as pure, mark
> functions that access global data as something else (global?) and weakly
> pure functions just aren't marked.

That seems like it would clearly mark out the three types of functions, though 
I'm not quite sure what all the implications are of having to mark in a 
function's signature that it accesses global data. That might be untenable. 
However, it would be a *lot* clearer than having to worry about what kind of 
pure a particular function is. It would also discourage accessing global state, 
which would generally be good - though shouldn't immutable global state still 
be 
accessible even from a pure function? Regardless, requiring "global" or some 
other keyword  would likely be too much of a breaking change at this point - 
though it might be worth it.

In any case, while I'm not sure I entirely understand the discussion in this 
thread, I like where it's going. As it stands, pure is too restrictive to be 
generally useful. It's still worth having, but it doesn't do much good 
generally. Being able to call weakly-pure functions from pure ones would 
improve 
things considerably, even if weakly-pure functions got no actual benefit from 
being weakly-pure.

- Jonathan M Davis

Reply via email to