Pure keyword for namespaces, classes, and methods. #4803
Unanswered
jlennox
asked this question in
Language Ideas
Replies: 2 comments
-
This feels like something that could be enforced by a custom analyzer. I personally don't think it would be broadly applicable enough. Also, the behavior described doesn't sound related to "purity". |
Beta Was this translation helpful? Give feedback.
0 replies
-
This may act better if CLR knows it and do some aggresive optimization. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Methods have been proposed in #776.
Often when reading code, which I do more than writing code, there's the question of dependency hierarchies. This can make reading code become an O(N2) problem due to how widely this can fan out. This creates the urge to create compile time isolation of specific code. One way to go about this is to add an additional project and move the class(es) into there. This, however, quickly makes organization difficult, badly increases compile time, and has other scaling issues.
One possible solution is to allow a namespace, or class, be defined as "pure." When a class is pure, the compiler would enforce that it does not reference other classes inside the same assembly. For example:
While this uses
Regex
it does not use anything else from the assembly. Thepure
keyword enforces this at compile time.The
pure
keyword on a namespace would ensure that nothing inside the same assembly, excluding contents of this namespace, can be referenced. I do not immediately have an opinion on how descendant namespaces should be handled.This helps with my problem because I know it's likely an end of the code hierarchy on that line, and I know there's an enforcement by the compiler, which the
[Pure]
attribute does not offer, that no one snuck in anything that changes this behavior.Beta Was this translation helpful? Give feedback.
All reactions