Since Go have functions as first class values, you could wrap you
function under another function and do the checks.
type fn func(int) int;
func check_fn(to_check fn) fn {
return func(i int) {
if i > 10 { panic("Argument checked"); }
ret = to_check(i)
if i < 10 { panic("Result checked"); }
}
}
--
André Moraes
http://andredevchannel.blogspot.com/
Those verifications in Java are done via Java Bytecode manipulation?
Like what HIbernate does for annotated classes?
Since Go have functions as first class values, you could wrap you
function under another function and do the checks.
type fn func(int) int;
func check_fn(to_check fn) fn {
return func(i int) {
if i > 10 { panic("Argument checked"); }
ret = to_check(i)
if i < 10 { panic("Result checked"); }
}
}
See also http://code.google.com/p/go/issues/detail?id=1765 which I think would permit (perhaps with a couple other little changes), doing this at runtime, without a pre-processor.
No, since it is a closure, you call check_fn and then just call the
value returned by check_fn which is a function.
> Aslo the dev must know explicitly that there is a check_fn func which is
> responsible for validation of fn.
Yes
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I completely agree that during production, asserts and panics must be used with care. Design by contract is used during development (debug builds and such) to help identify bugs on a running system by failing fast and recording any possible software state.
I don't really think this is a black and white issue. There are situations where asserts (fail fast methodologies) on productions systems is the correct thing to do (like a car computer sensing something fatally wrong). There are also situations where asserts is not beneficial to the product, and handling the error instead is the correct answer.
Here is the repository:
https://github.com/Parquery/gocontracts
We are thinking about implementing the invariants in a similar way. Please have a look at this post if you'd like to discuss the details or contribute:
https://groups.google.com/forum/?hl=uk&nomobile=true#!topic/golang-nuts/zKQA0Lh116k