-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: @expect macro #1594
RFC: @expect macro #1594
Conversation
I like it. |
Java, for example, has different artefacts for these use cases, but for a language with macros, there doesn't seem to be much value in separating these two. The only addition I would want in the @expects use-case is the ability to globally turn off expectation checking (for when performance is at a premium, the code is debugged, and all user input is separately sanitised). Even that seems sensible to implement within @asserts. |
The error message is indeed the only functional difference so far. The reason that I submitted this pull request is because I think that there is an important distinction to be made in intent and interpretation between the two cases. From the point of view of design by contract,
Perhaps some of these distinctions should be present in the code already. |
Yes, it is a good idea simply for the purpose that it gives a more appropriate error message. |
I'm not sure the error message is that much clearer, especially to a newbie who is unlikely to be attuned to the subtle differences between expect and assert (it's like a fine point of English grammar more than code structure). I guess I'm not convinced by this one. |
I do think that the user deserves something clearer than I actually have an old (in julia terms :) project call
would make a failed
I've been thinking to dust it off and see if I could make it available. |
It seems there's a bit to discuss here. Perhaps I'll take it up on julia-dev. |
I've found the
@assert
macro very useful for writing assertions in a compact and readable way. The same kind of format would be useful also when the condition to be checked is not really an assertion.I therefore propose an analogous
@expect
macro, to e.g. check for fulfillment of preconditions to a function call. If an@expect
fails, it is the caller of the function that is to blame,as opposed to an assertion failure, where there is a bug in the function itself.
Compare e.g. the somewhat readable code
to the much bulkier version without
@expect
:The latter takes longer time both to write and to read.
Do people think this is a good idea? Thoughts?