3 ms·
Right. Pure functions make it considerably easier to reason about code, even in the absence of concurrency. It's a shame D's pure modifier (to statically guara
by MaxBarraclough 4y ago
Right. Pure functions make it considerably easier to reason about code, even in the absence of concurrency.
It's a shame D's pure modifier (to statically guarantee purity) isn't available in many other languages. [0] SPARK Ada has something similar in that functions must always be pure, forcing procedures to be used for impure functionality. [1] edit I think that's mistaken, SPARK appears to permit functions to read globals but not to modify them.
edit John Carmack has written about this kind of thing. From [2]:
> if a function only references a piece or two of global state, it is probably wise to consider passing it in as a variable. It would be kind of nice if C had a "functional" keyword to enforce no global references.
[0] https://dlang.org/spec/function.html#pure-functions https://dlang.org/spec/function.html#pure-functions
[1] https://learn.adacore.com/courses/intro-to-spark/chapters/01_Overview.html https://learn.adacore.com/courses/intro-to-spark/chapters/01...
[2] https://cbarrete.com/carmack.html https://cbarrete.com/carmack.html