Top
Best
New

Posted by rockyj 10/25/2025

Result is all I need(rockyj-blogs.web.app)
113 points | 97 commentspage 2
tyteen4a03 2 days ago|
Smells like something that Effect-TS is designed to solve in the TypeScript world.
taeric 2 days ago||
It is always funny to see that we try and force formulas to the early elementary shape that people learn. Despite the fact that chemistry, biology, physics, etc. all have advanced shapes for equations that do not have the same concerns.

Similarly, when constructing physical things, it is not uncommon to have something with fewer inputs than outputs. Along with mode configured transfer of input to outputs.

time4tea 2 days ago||
Result<T> is a built-in in kotlin, but this enforces that the error type is a Throwable

If you fancy that an error could be just a type, not necessarily a Throwable, you might like Result4k - it offers a Result<T,E>

https://github.com/fork-handles/forkhandles/tree/trunk/resul...

disclaimer: I contribute to this.

RedNifre 2 days ago||
Nice, what's the KMP plan there?

We currently use https://github.com/michaelbull/kotlin-result , which officially should work on KMP, but has some issues.

LelouBil 2 days ago||
In Kotlin, my go-to library is https://arrow-kt.io/
Thorrez 2 days ago||
The imperative code has

    // log exception
which doesn't exist in the Result version.
hotpotat 2 days ago||
With regard to AI, why not throw this whole article in an .md file and point CLAUDE.md to it? Codex is better at following rules so maybe you’d have more luck with that. But yeah, AI won’t code your way by default. People expect way too much out of the interns, they need direction.
ActionHank 2 days ago|
This is one of the issues with LLMs in dev IMO.

You either have the case that tech moves on and the LLM is out of date on anything new, so adoption slows or you have tech slowing down because it doesn't work with LLMs so innovation slows.

Either way, it's great if you're working on legacy in known technologies, but anything new and you have issues.

Can I write a spec or doc or add some context MCP? Sure, but these are bandaids.

anon-3988 2 days ago||
With the ? syntax in Rust results and exceptions are the same thing. I posit that the former is superior. It is unfortunate that results have worse performance but I don't see any reason why. Results that bubbles up all the way ought to be identical to an uncaught exception.
rcxdude 2 days ago|
Exceptions can tradeoff happy-path performance for more overhead on the slow path. For example, an exception implementation can make it so that callers can assume the 'Ok' result always appears, because an exception causes a seperate unwinding mechanism to occur that walks the stack back, bypassing that entirely. In contrast every caller to a function that returns a Result must have a branch on that result, and this repeats for each part of the callstack.

This also means that exceptions can have stacktraces that only incur a cost on the unhappy path and even only if that exception is uncaught. While if you want a trace for a bad Result you are going to be doing a lot of extra book-keeping that will be thrown away

In general I agree that Results are the better abstraction, but there are sadly some tradeoffs that seem to be hard to overcome.

thinkharderdev 2 days ago||
This depends a lot of what you are using exceptions for. I think in general the branch on Ok/Err is probably not meaningful performance-wise because the branch predictor will see right through that.

But more generally the happy-path/error-path distinction can be a bit murky. From my days writing Java back in the day it was very common to see code where checked exceptions were used as a sort of control flow mechanism, so you end up using the slow path relatively frequently because it was just how you handled certain expected conditions that were arbitrarily designated as "exceptions". The idea behind Result types to me is just that recoverable, expected errors are part of the program's control flow and should be handled through normal code and not some side-channel. Exceptions/panics should be used only for actually exceptional conditions (programming errors which break some expected invariant of the system) and immediately terminate the unit of work that experienced the exception.

_ZeD_ 2 days ago||
gosh...

        try {
            val user = authService.register(registrationRequest.email, registrationRequest.password)

            return user
        } catch (exception: Exception) {
            // log exception
            throw exception
        }


no, no, no!

the whole point of the exceptions (and moreso of the unchecked ones) is to be transparent!

if you don't know what to do with an exception do NOT try to handle it

that snippet should just be

    return authService.register(registrationRequest.email, registrationRequest.password)
CGamesPlay 2 days ago||
I'm gonna plug my favorite note on this topic: https://ericlippert.com/2008/09/10/vexing-exceptions/

Both snippets suffer from being too limited. The first, as you point out, catches too many exceptions. But the second.... What happens if the email address is taken? That's hardly exceptional, but it's an exception that the caller has to handle. Your natural response might be to check if the email address is taken before calling register, but that's just a race condition now. So you really need a result-returning function, or to catch some (but probably not all) of the possible exceptions from the method.

noduerme 2 days ago||
The way I usually structure it is that the only exception would be some type of failure to connect. Any actual error thrown by the service comes back as a result.error, and any failure (like email address taken) comes back as result.fail. This way you can separate it into (1) connection problem, (2) backend error/bug/database offline/etc, (3) both of those are fine but the backend doesn't like the input.
rockyj 2 days ago||
I agree, this was just a sample code to show how usually imperative if / else / try / catch code is written. What is also possible is we catch the exception, log it and throw another one.
lachenmayer 2 days ago||
Stick your services into the type too, and you have `Effect`[0], the ultimate monad :)

[0]: https://effect.website/

another_twist 2 days ago||
I have had to write a Result abstraction multiple times. Honestly I think it should be part of standard java much like Optional.
greener_grass 2 days ago|
Result is great but it ideally needs extensible union types (polymorphic variants) plus exhaustive pattern matching to work well.
More comments...