r/ProgrammerHumor • • Oct 17 '26

instanceof Trend thatsAFunnyThingThatHappenedOnce

Post image
4.6k Upvotes

524 comments sorted by

View all comments

Show parent comment

3

u/Cylian91460 Oct 18 '26

or Result, aka "encode the possibility of failure in the return type of the function" aka what the functional programming world has done for ages.

Like Optional in java?

24

u/[deleted] Oct 18 '26

[removed] — view removed comment

2

u/guyblade Oct 18 '26

C++ has a couple of versions of this floating around absl::StatusOr, boost.Outcome, std::expected, and probably others that I'm not aware of.

4

u/[deleted] Oct 18 '26

[removed] — view removed comment

1

u/Hubble-Doe Oct 18 '26

Speak for yourself, I've been working with Java for a few years and think exceptions are pretty neat! they can be passed through calls implicitly without much mental overhead and boilerplate, and when you handle them you still get a nice helpful stacktrace.

3

u/koko775 Oct 18 '26

Result<Foo> ~= Either<Foo,Error>

2

u/Celarion Oct 18 '26

Like monads, with your result boxed as Ok, and any error boxed as Err

2

u/0tter501 Oct 18 '26

Java has added functional programming yes, but Optional is not result, as result stores either the result or the error

optionals store one type of failure value, results store many types of failure values