I've found myself wanting to write contracts on private functions, but I
don't want to pay the performance cost during normal operation. What I've
been doing is making a `def/c` macro which looks exactly like
`define/contract` but is wired up to `define` and discards the contract.
When I want to enable these private contracts (e.g. when running tests or
debugging a problem) I simply change the source code of `def/c` so that it
is wired up to `define/contract` and the contract is checked. Here is an
example: http://pasterack.org/pastes/4224
Manually changing the source code of `def/c` has worked fine so far, but I
would love to be able to do something like "raco test
-with-private-contracts (package1, package2) ./" instead.
I prefer this approach over putting the contracts in comments, because
comments have less precise meaning and may become subtly inaccurate if the
implementation of the function changes.
I wonder if other people want to write code the same way. If so, having a
standard, shared `define/contract/private` could be useful. This would
allow us to do things like
1) Build a contract-aware linter.
2) Build a "minimally intrusive type system." (This might also be called a
"linter"; I'm not sure if there is a definite line separating the two.)
3) Better IDE support
4) If I suspect a package I am using has a bug, I might be able to confirm
(but not deny) that suspicion by turning on private contracts for that
package and seeing if a violation is reported.
So I guess if I'm the only one interested in this then just ignore me. If
there's already work in this area, great! Please point me to it. But if
there's interest and a need, I'd be happy to help however I can.
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/5e8ece69-bbb7-4dbf-933f-52cc097291d2%40googlegroups.com.