by chadnickbok · 15y ago · 0 comments
int some_function( some_variable ) {
if (some_variable) {
b = 1;
} else {
b = 2;
}
log("Its important I log that I'm returning %d\n", b);
return b;
}If its not obvious why this is superior...
func someFunction(b bool) (i int) {
defer func() {
log.Printf("I'm returning %d", i)
}()
if b {
return 1
}
return 0
}
For more on defer, see this blog post: http://blog.golang.org/2010/08/defer-panic-and-recover.html some_function = function() {
if (...) return 1;
if (...) return 2;
}.log("It's important I log that I'm returning"); int some_function( some_variable ) {
log("Its important I log that I'm returning %d\n", (some_variable ? 1 : 2));
return (some_variable ? 1 : 2);
}