Less cluttered error handling in cells. #99
Replies: 4 comments 2 replies
-
Oops, forgot to share the notebook. Should be public now. |
Beta Was this translation helpful? Give feedback.
-
I have to say I like using exceptions (in Go translated to Would something like this be ergonomic to you: import (
"fmt"
"github.com/janpfeifer/must"
)
func f(fileName string) (int, error) {
return 0, fmt.Errorf("File %q is no good here", fileName)
}
%%
value := must.M1(f("hello_world.txt"))
fmt.Printf("value=%d\n", value) Which outputs:
And, a slightly different version, using the
Notice there is only one final Fundamentally it's doing the same thing:
Should Any thoughts ? |
Beta Was this translation helpful? Give feedback.
-
So ... this is a bit philosophical. But let me start with a couple of technical comments:
Now the philosophical (choice) aspects (it will sound opinionated, but let me say in advance I'm not religious about these things, and really open to changing my mind if there are good arguments):
Ok, with that in mind ... I'm hesitant to include Any thoughts ? |
Beta Was this translation helpful? Give feedback.
-
@janpfeifer We had snowstorm today here in northwestern Vermont, so I had some time to spend trying out various error handling methods and syntaxes. I don't think any new magics would add real value just for error handling. I'll be using either the tried and true func Check(err error, msg string) {
if err != nil {
panic(fmt.Errorf("%s: %v", msg, err))
}
} You wrote:
Well, one simple and very general approach is to use your shell command mechanism to call a user program that generates code. That's essentially all With var generated string = `
// !! mycodegenerator options args ...
// Generated output goes here.
` In the above, I wrapped it all in backquotes to prevent the generated code from being executed immediately. Seems to me one would usually want to look at the result before trying to run it. Or maybe the generator output should go into a new cell just after the current one. Obvious, one could do most of this already in |
Beta Was this translation helpful? Give feedback.
-
I put a notebook in CoLab that demonstrates a possibly useful way to reduce the visual clutter from the usual way of handling errors in Go. I think it's especially applicable to notebooks, where some may perceive that Go's verbosity suffers in comparison to Python.
Please take a look and let me know if it seems worth incorporating into some
%
magic forgonb
.If so, I'd be happy to look into implementing the magic and submitting a pull request.
Beta Was this translation helpful? Give feedback.
All reactions