3 ms·
Really? Really? foo()?.bar()?.baz()? This is somehow less clear, and somehow "more debuggable" than a, err := foo() if err != nil { nil,
by stouset 10y ago
Really? 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