3 ms·
Even something like foo::<‘_, [T]>() is just not that hard to follow. Again, the symbols involved all compose nicely and are unambiguous. And frankly, you just
by stouset 2y ago
Even something like foo::<‘_, [T]>() is just not that hard to follow. Again, the symbols involved all compose nicely and are unambiguous. And frankly, you just don’t need something like that all that often (and when you do, there are usually other alternatives if you’re really put off by the symbols.
- johnisgood 2y agoSomeone mentioned the use of ")?)?" (in terms of error handling), I am quite put off by this, too. :P Anyways, I will try to look for the code, it is somewhere in my comment history but I have left way too many comments, so no promises.
- stouset 2y agoI would one million percent rather type (and read) foo(bar()?)? over something like if a, err := bar() { return nil, err } if b, err := foo() { return nil, err } But also even better is just let a = bar()?; let b = foo()?;
- deleted 2y ago[deleted]
- johnisgood 2y agoI prefer ("if a, err := bar() {"), the same things you said applies here, too. I write a lot of Go and I can glance through it quickly, there is no cognitive overhead for me. Edit: actually, it was someone else who said this: "Human brain has a funny way of learning how to turn off the noise and focus on what really matters.".
- stouset 2y agoThe difference is, there is no room for bugs with ?. Zero. None. I have fixed (and frankly, caused) many bugs in golang code where people’s brains “turned off the noise” and filtered out the copypasta’d error handling, which overwrote the wrong variable name or didn’t actually bubble up the error or actually had subtly wrong logic in the conditional part which was obscured by the noise. Frankly, learning to ignore that 80% of your code is redundant noise feels to me like a symptom of Stockholm syndrome more than anything else. One symbol to replace three lines of identical boilerplate is no less explicit and dramatically clearer.
- jicea 2y agoIt's even nicer in Rust: there can be an "implicit" conversion between the error raised by foo and bar: fn foo() -> Result<(),FooError> bar()? fn bar() -> Result<(),BarError> If FooError can be created from BarError, the compiler will insert the conversion call and errors bubbles up nicely.
- johnisgood 2y agoIs it not caught by the compiler or linter though? Even variable shadowing is caught.
- stouset 2y agoSome things are. Some things aren’t. At one point, you could write nil, err without the return and it would happily compile. It’s also tragically easy for actual logic bugs to be obscured by all the boilerplate. It’s not like three lines of error handling copypasta is some optimal amount. If golang required ten lines of boilerplate error handling, you’d still have just as many people arguing in favor of it because they “like it to be explicit” when it reality it’s verbose and the real underlying argument is that it’s what they’ve grown accustomed to. `?` is no less explicit, but it is less unnecessarily verbose.
- johnisgood 2y agoWhat I can say here is that I am not one of these people who would argue in favor of Go's error handling were it 10 lines. shudders. I would definitely not use it, just like how I do not use Java for quite many reasons (unless I get paid for it, but would rather not). :P