Purity inference #9225
-
Purity inference in C# could be implemented by providing a new keyword, such as pure, placed in the same location as async. (Because async functions would never be pure, this would not lead to less readable function declarations.) There is only one constraint that must be enforced to achieve this feature: pure functions could only call other pure functions, properties, etc. public pure int MethodName() Purity inference would enable a lot of beneficial features:
And it should be possible to incrementally adopt it, similar to nullable reference types. Additionally, it should be completely inferable. Probably the biggest benefit would be that it encourages a better coding style by motivating developers to actively separate pure and effectful code, thereby reducing bugs and improving maintainability. It is in line of adapting functional programming paradigms when beneficial. Inspired by: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
See: #1157 |
Beta Was this translation helpful? Give feedback.
See: #1157