Hacker News new | past | comments | ask | show | jobs | submit
> - go style err!=nill style exception handling

Is this not widely considered to be the ugliest part of the language? Why do you prefer having to do this manually?

As someone who is primarily a Go dev, I never understood this criticism and have never seen a language do it any better (but I'm open to suggestions). I think try/catch is worse. I kinda like JS's promise syntax with the `.then()` and `.catch()`, but it doesn't appear that different to Go's approach.
Returning Result/Options that the compiler forces you to check so you can't forget.

Common in ML-family languages and Rust. They've been brought into most mainstream languages like Java by now because of how useful they are.

Ahhhh, got it: enforced correctness. Fair enough, I can definitely see the benefit of that. I do wish Go had more ways to do that, like first-class enum support, exhaustive switch cases, and, yeah, forced error handling. golangci-lint does a lot of this heavy lifting on behalf of the Go compiler, but it would be nice to have the compiler enforce it.
I hope that doesn't mean the compiler inherits the extra work

I'm considering glojure as an interesting new hobby language to try because it's benchmarks are impressive

If the go compiler ends up bloating itself with checks its static analyser could/should have done it would be a shame

Odin has @(require_results) that forces you to do something with returned values (e.g. T, Maybe(T), (T, bool))

Where Maybe is a polymorphic union of T and nil but the core library returns either (T, bool) or (T, E) where E is an error enum.

Personally I think Go style is worse, because the runtime and compiler don't force you to handle the error. I just had to fix a critical issue because a dev forgot to check the result coming from a function, exceptions would have forced it to happen.
> I kinda like JS's promise syntax with the `.then()` and `.catch()`, but it doesn't appear that different to Go's approach.

These days async/await is first-class and the function-based callback form of promises is largely discouraged. And for, at least in part, the same reason: it's harder to enforce correctness.

It is, which is why the or_return[1] keyword was created.

[1]: https://odin-lang.org/docs/overview/#or_return-operator

Errors as values instead of some special language construct is generally a nice thing (IMO)
Exceptions are values. There's nothing different between:

    T someFn() throws E;
    fn someFn() -> Result<T, E>;
    func someFn() (T, E)
In only one of those examples do you get a T that's invalid.
True, Go does require you to follow a convention here (dont use T if err is not nil). In practice it works pretty well, though obviously not bullet proof.

I believe some exceptional languages are similar, like Ruby. If you rescue but dont abort, the variable on the left hand side gets a nil when that may otherwise not be possible. Of course, that is handled cleanly as its own error.

I don't see how. Unless it's the Go example where you get (nil, err)?