7 ms·
I find the Go version to be easier to debug though.
by namelezz 10y ago
I find the Go version to be easier to debug though.
- junke 10y agoI hope so, because it is more subject to accidental copy-paste bugs.
- pcwalton 10y agoWhy? Can you explicitly name a type of mistake that might happen and explain how Go solves it in a way that Rust does not?
- namelezz 10y agoIt's not really a mistake. Just coding preference. For example: do_A()?.do_B()?.do_C()?. With the one line statement like that, when weird things show up, I don't really know if it's caused by bugs in do_A, do_B, or do_C. The linear layout of Go code lets me go through each do_X call line by line and setting break points is also easier. The problem here is when I need to investigate the chain do_A()?.do_B()?.do_C()?., I may have to rewrite that statement.
- pcwalton 10y agoI agree that we should have good debugging tools for this (in particular, break on error return). But note that you can break on function calls and use "finish" to effectively go call by call to see where the error is today.
- namelezz 10y ago> use "finish" to effectively go call by call Great tip. Thank you for the hint.
- nercury 10y agoBut consider that the Rust does not have null, so every case where you need to step over the code and see if it does the right thing when value is null does not need debugging!
- masklinn 10y agoNothing prevents you from writing let a = foo()?; let b = a.bar()?; let c = b.baz()?; if that's what you want, not sure how the Go version would be easier to debug beyond that, and you can easily perform that transformation when you actually need to debug that code if the "pointfree" version hinders that.
- Matthias247 10y agoIf you want to set a breakpoint on the error then I guess that's not possible in your form. I don't know what ? really does but I guess it somehow short-circuits the current block in the error form and returns the error. I also sometimes include log statements in specific error branches for debugging and delete them afterwards. That's trivially possible in the Go version but requires more effort in the shorter variants (e.g. also if the funcitons throw exceptions instead of returning errors in other languages).
- junke 10y agoThat's trivially possible in the Go version because you paid the cost of adding explicit error handling upfront. It takes more effort to wrap a handler for a specific exception because there was no need originally to write a handler in that place.
- masklinn 10y ago> If you want to set a breakpoint on the error then I guess that's not possible in your form. You can just macroexpand ? and do that (although I don't know that there are tools doing macroexpansion currently). > I don't know what ? really does It's really nothing special, `a?` simply expands to: match a { Ok(val) => val, Err(err) => { return Err(From::from(err)) } } > also if the funcitons throw exceptions instead of returning errors in other languages ?
- Matthias247 10y ago> It's really nothing special, `a?` simply expands to: Ok, that's what I expected > ? I meant if I have foo().bar() in C# or Java and foo() throws it's equally hard to change the code to add error handling in between since I would need to add a try/catch clause and rethrow the error.
- stouset 10y agoReally? Really? foo()?.bar()?.baz()? This is somehow less clear, and somehow "more debuggable" than a, err := foo() if err != nil { nil, err } b, err := a.bar() if err != nil { nil, err } c, err := b.baz() if err != nil { nil, err } return c, nil One of these obviously has no bugs. There is literally nothing to debug. The other has no obvious bugs. Oh, except look again, I accidentally forgot to return from those error-handling-statements and now I have what should have been a completely avoidable bug. Ask me how many times I've been bitten by this.
- iand 10y agoOK, how many times have you been bitten by it? It doesn't even compile so I doubt you have run into it in real code.
- andrewchambers 10y agothat problem does compile in Go, and i have done it before (maybe with single err and not a comma). iirc there are go vet checks to catch that.
- iand 10y agoSee my other comment for runnable example. https://news.ycombinator.com/item?id=12925765 https://news.ycombinator.com/item?id=12925765