Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • So a pure constructor is a pure method which is allowed to change the state of the current class, as long as it satisfies the other conditions of being pure? BTW, The property is mutable because I wanted to emphasize that this class itself is not pure. Commented Jul 1, 2014 at 16:36
  • @p.s.w.g: You created an interesting question which probably has to be answered by Microsoft. Suppose the constructor invoked a method that modified the mutable property; would the constructor still be pure? I think technically it would not be, even though the modification is "invisible" to external viewers. Since there is no other code invoked in your original example, it must be pure by any definition I can think of. Commented Jul 1, 2014 at 17:07
  • @p.s.w.g: Except that the property set is also a method call.. I think you should ask on the MSDN forums. Commented Jul 1, 2014 at 17:11
  • I guess if the central idea of purity is whether or not the method makes any observable changes, then in that sense, regardless of whether or not it calls non-pure methods, as long as the changes can't be observed by any caller, it would still be a pure method. Commented Jul 1, 2014 at 18:55
  • @p.s.w.g: That is the abstract definition. But if I was writing an analyzer for these things, probably an non-pure method call would also be considered to make the caller non-pure. Just for simplicity of implementation. Then the question is, is a constructor a normal method call, or how deep does the analysis go. Commented Jul 2, 2014 at 2:54