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. > > -Steve
This is interesting, I'm not sure if either of these approaches could make it into D2, though a conservative approach was originally taken only because it was the most easy to prove. I also find it interesting that D actually takes the 3-stage approach to several things. mutable, const, immutable; @safe, @trusted, @system. And this being unpure, contained, pure. D recognizes the importance of these stages in other areas, so I feel it would be a miss if there is not a good reason the proposal doesn't work. Sadly what you learn from one of the stated areas (mutability, safety, purity) can't be applied to the other. But the pattern is there.