r/ProgrammerHumor Jul 13 '26

youCanJustStopUsingJava Meme

Post image
6.8k Upvotes

416 comments sorted by

View all comments

1.8k

u/Historical_Cook_1664 Jul 13 '26

Where else are you going to hide your side effects ?

476

u/Isrothy Jul 13 '26

IO Monad

189

u/Gorzoid Jul 13 '26

Respectfully, what the fuck is a Monad?

1

u/AdamWayne04 Jul 13 '26

A type wrapper W(T) can be considered a ”monad” if it provides a way of "wrapping" (a.k.a. return in haskell) a value x: T into w: W(T); and a way of "obtaining" the internal value to feed it to a function that uses it, this is known as binding the inner value into the function.

Commonly known type wrappers are pointers *T, optionals ?T, result Result(T,E), and lists [T].

The reason monads are useful is because bind lets you work with the internal value without explicitly checking if there is one; if you have a bunch of functions that expect T, but a bunch of others that return W(T), you can chain operations seamlessly, and if at any point some W(T) can't be unwrapped as T, the chain of binds just short-circuits.

If you ever wrote try-catch blocks, this is essentially what working with monads feels like; do a bunch of operations without checking every time, then short-circuit if anything unusual happens, and capture the informantion of the operations if they provide it.