Discussion: map methods #926
Replies: 10 comments
-
Sounds like a good case for a custom analyzer. |
Beta Was this translation helpful? Give feedback.
-
Sounds like |
Beta Was this translation helpful? Give feedback.
-
Another one to add to your collection, @jnm2 😆 I like the idea of a keyword that indicates a method must only use its parameters to determine its result, but |
Beta Was this translation helpful? Give feedback.
-
No kidding! 😆 Definitely agreed about calling it |
Beta Was this translation helpful? Give feedback.
-
Agreed, I do believe this falls under the definition of "pure" methods. The attribute already exists and it might be nice if the compiler could check that via a warning wave. But beyond that it's perfect fodder for an analyzer. It looks like you've already started down the path of testing method purity, but it doesn't look like you're basing any of that on the existing |
Beta Was this translation helpful? Give feedback.
-
You are correct. I took an alternative approach: static methods must be pure by default and have to be annotated with |
Beta Was this translation helpful? Give feedback.
-
Yes, this sounds like you want a "pure function" in the parlance of language nerds. |
Beta Was this translation helpful? Give feedback.
-
I don't believe My understanding is that What OP appears to be asking for is a way to signify that this method does not take any additional inputs than what it was explicitly fed through it's argument list. Those are two different things. |
Beta Was this translation helpful? Give feedback.
-
If that's the case, that means |
Beta Was this translation helpful? Give feedback.
-
Right, looks like another thing the Contracts team only got halfway through, then.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Take the following class
I want M to be a map. That is, if called with inputs x and y then the output will only depend on x and y.
However, someone might come along and change M to be:
This still works technically if
_c
is 0, but if they ever call M2(), the mapping of M() is broken. So I would like this to raise a warning or error.This I would say should be fine though:
I'd like a way, if this possible or even makes sense, to mark a method as a map. Either with a keyword, something like
public static map int M(int x, int y) { .. }
Or maybe an attribute, something like
It would then be a compiler warning to change M in such a way that it's output is dependent on anything other than it's inputs (in this case x and y).
Does this make sense?
Is it feasible?
Beta Was this translation helpful? Give feedback.
All reactions