www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Weak Purity Blog Post

reply sarn <sarn theartofmachinery.com> writes:
D's implementation of functional purity supports "weak" purity - 
functions that can mutate arguments but are otherwise 
traditionally pure.

I wrote a post about some of the practical benefits of this kind 
of purity:

https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
Mar 27 2016
next sibling parent reply Joakim <dlang joakim.fea.st> writes:
On Monday, 28 March 2016 at 01:44:02 UTC, sarn wrote:
 D's implementation of functional purity supports "weak" purity 
 - functions that can mutate arguments but are otherwise 
 traditionally pure.

 I wrote a post about some of the practical benefits of this 
 kind of purity:

 https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
Very well-written, someone post it on Reddit.
Mar 27 2016
parent reply deadalnix <deadalnix gmail.com> writes:
On Monday, 28 March 2016 at 05:21:36 UTC, Joakim wrote:
 On Monday, 28 March 2016 at 01:44:02 UTC, sarn wrote:
 D's implementation of functional purity supports "weak" purity 
 - functions that can mutate arguments but are otherwise 
 traditionally pure.

 I wrote a post about some of the practical benefits of this 
 kind of purity:

 https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
Very well-written, someone post it on Reddit.
https://www.reddit.com/r/programming/comments/4c8zs6/how_dirtying_pure_functions_a_little_can_be/
Mar 27 2016
next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 3/27/2016 10:41 PM, deadalnix wrote:
 On Monday, 28 March 2016 at 05:21:36 UTC, Joakim wrote:
 On Monday, 28 March 2016 at 01:44:02 UTC, sarn wrote:
 D's implementation of functional purity supports "weak" purity - functions
 that can mutate arguments but are otherwise traditionally pure.

 I wrote a post about some of the practical benefits of this kind of purity:

 https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
Very well-written, someone post it on Reddit.
https://www.reddit.com/r/programming/comments/4c8zs6/how_dirtying_pure_functions_a_little_can_be/
Queue my usual harangue: Articles do MUCH MUCH better on reddit if, when posted, a brief description of the content of the article is also posted. Like what sarn posted here. Not doing so seriously blunts the value. People need a reason to click on the article. It's why when you google something, you don't just get a list of links. You get a blurb with each link.
Mar 28 2016
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 3/27/2016 10:41 PM, deadalnix wrote:
 https://www.reddit.com/r/programming/comments/4c8zs6/how_dirtying_pure_functions_a_little_can_be/
BTW, thanks for posting it.
Mar 28 2016
prev sibling next sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 3/27/2016 6:44 PM, sarn wrote:
 D's implementation of functional purity supports "weak" purity - functions that
 can mutate arguments but are otherwise traditionally pure.

 I wrote a post about some of the practical benefits of this kind of purity:

 https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
It's a nice article, you should put your name on it as the author!
Mar 28 2016
prev sibling next sibling parent reply ag0aep6g <anonymous example.com> writes:
On 28.03.2016 03:44, sarn wrote:
 https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
From there:
 Well, you can get the usual (“strong”) purity guarantee just by making all
pointer or reference type arguments const.
Indirections in the return type also play into this. David Nadlinger explains this in his article on the matter: http://klickverbot.at/blog/2012/05/purity-in-d/#indirections-in-the-return-type
Mar 28 2016
parent sarn <sarn theartofmachinery.com> writes:
On Monday, 28 March 2016 at 09:59:12 UTC, ag0aep6g wrote:
 On 28.03.2016 03:44, sarn wrote:
 https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
From there:
 Well, you can get the usual (“strong”) purity guarantee just 
 by making all pointer or reference type arguments const.
Indirections in the return type also play into this. David Nadlinger explains this in his article on the matter: http://klickverbot.at/blog/2012/05/purity-in-d/#indirections-in-the-return-type
Thanks. I updated the post.
Mar 29 2016
prev sibling next sibling parent =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
On Monday, 28 March 2016 at 01:44:02 UTC, sarn wrote:
 I wrote a post about some of the practical benefits of this 
 kind of purity:

 https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
Great. It would be nice if you added a section that discusses purity in collaboration with allocators. See discussions: http://forum.dlang.org/post/yvwtjybwphxovrxavdiw forum.dlang.org http://forum.dlang.org/post/ejaarbdzcqgqhkxladoz forum.dlang.org and https://github.com/D-Programming-Language/druntime/pull/1183#issuecomment-202444315
Mar 30 2016
prev sibling parent reply Jon D <jond noreply.com> writes:
On Monday, 28 March 2016 at 01:44:02 UTC, sarn wrote:
 D's implementation of functional purity supports "weak" purity 
 - functions that can mutate arguments but are otherwise 
 traditionally pure.

 I wrote a post about some of the practical benefits of this 
 kind of purity:

 https://theartofmachinery.com/2016/03/28/dirtying_pure_functions_can_be_useful.html
Nice article. A suggestion: The point about improved testability when designing for purity is well made. In D, this is further supported by the ability to write and place unit tests alongside the functions themselves. That's my personal opinion at least - because unit test are so easy to write in D, it encourages design for testability. My suggestion is to add a note about this to the post. --Jon
Mar 30 2016
parent sarn <sarn theartofmachinery.com> writes:
Yeah, there's a lot more stuff I could have talked about, but I 
think I'll leave it for other posts.

About testing, I think the way protection works in D (i.e., 
private members are accessible within the same file) is 
important, too.  I was a bit suspicious of that feature when I 
first looked at D (coming from C++) but now I actually like the 
kind of project structure it leads to.  I think better 
testability is just one of the advantages, but I'll write up a 
full blog post sometime.
Mar 30 2016