Passing array as const slows down code?

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Fri Apr 27 10:25:30 PDT 2012


On 27/04/12 19:08, Steven Schveighoffer wrote:
> weak purity, I think, is one of the most revolutionary ideas to come from D.
> Essentially, we get compiler-checked pure functions that can be written
> imperatively instead of functionally.

I do agree with that; it's a very attractive aspect of D that a function or 
object can be internally imperative but pure as far as the outside world is 
concerned.  Seeing that documented in Andrei's writings was another "Wow!" 
moment for me about D. :-)

What concerned me here was that the way my reputation() function was set up 
actually did change the public state of the object, which to my mind isn't even 
weakly pure.  But I just wrote a fix which, contrary to my fears, didn't affect 
the speed of the program.

> If the function is weakly pure, then it cannot be optimized based on purity, so
> I don't think there is any way marking it pure *hurts*.

I was more concerned that the compiler wasn't identifying what to me was a 
violation of purity.  I'm fairly sure I can also find a way to make some of 
those "nothrow" functions throw an error ...


More information about the Digitalmars-d-learn mailing list