Replies: 3 comments 15 replies
-
The thing you noticed about The docs are far too vague on the "side effect" warnings right now (thanks for helping me realize this!). In general, reasoning about mutation is supported by CrossHair, and that's why we have things like class invariants. There are two real requirements that I'm trying to express with this warning:
In fact, probably the docs should instead just state these two bullets above, explicitly. WDYT? |
Beta Was this translation helpful? Give feedback.
-
@amacfie that would be precisely the case for `Const[T]` or `ReadOnly[T]`,
wouldn't it?
(Edit: corrected the addressee)
|
Beta Was this translation helpful? Give feedback.
-
Here are the slides from a lecture I had at the university (this is the newest version from 2020): https://ethz.ch/content/dam/ethz/special-interest/infk/chair-program-method/pm/documents/Education/Courses/AS2020/Coop/lecture%2006%20-%20object%20structures.pdf It might be a quick introduction for the interested people not familiar with the details. The section "6.3 Read-only Types" is relevant for this discussion. |
Beta Was this translation helpful? Give feedback.
-
According to PEP 316,
post: ...
andpost[]: ...
are equivalent, but CrossHair treats them differently, specifically in the former case input objects are assumed mutable. Since the CrossHair docs say "never target code that can directly or indirectly call mutating side-effects", should CrossHair default to assuming inputs are immutable? Currently with icontract I don't see a way of expressing mutability or immutability so it always assumes mutability.Addendum: How are class invariants supposed to work if CrossHair isn't intended for side-effects?
Beta Was this translation helpful? Give feedback.
All reactions