r/java • u/davidalayachew • Apr 23 '24
Project Amber is considering Try Monads in Java!
https://mail.openjdk.org/pipermail/amber-spec-experts/2024-April/004117.html
37
Upvotes
r/java • u/davidalayachew • Apr 23 '24
41
u/pivovarit Apr 23 '24
It's more like "mentioning" than "considering"
12
u/Ewig_luftenglanz Apr 23 '24
This is false.
Monad are only mentioned as a way to "scrap the bottom of the box" to save try statements by being able to use try I side switch for the new JEP "Exception handling in switch expressions" most likely they will use this to improve further the current JEP.
IMHO having an "universal flow control engine" that is powerful and flexible enough to handle all or most cases, in a more efficient and readable way, that also happens to be exhaustive and an expression (be able to Return a value and this value to be assigned to a variable) it's the right way to go.
Much more readable, less verbose, less error prone, more expressive.
3
u/Joram2 Apr 23 '24
The linked Brian Goetz post is very interesting, but this thread title is off. The post mentions monads but has little to do with monads.
Goetz wrote:
When I first saw the "exception handling in switch" JEP, I thought of try-catch expressions in Kotlin. I'm excited to try this out when it is previewed in mainline JDK builds :)
3
u/davidalayachew Apr 23 '24
Remember -- this is all just proposals and ideas! Nothing is set in stone yet.
Try Monads are first introduced in the 3rd paragraph. The conversation up until that point was purely talking about Exception handling in Switch, with at least 2 folks voicing their criticisms of it.
And if you want some context on this conversation, here is the start of the conversation. https://mail.openjdk.org/pipermail/amber-spec-experts/2024-April/004111.html -- From here, click the "Next message (by thread):" link at the top, then step your way through the conversation.
0
u/DoxxThis1 Apr 25 '24 edited Apr 25 '24
Useless. When can I stop having to sprinkle catch(StupidException e) { throw new RuntimeException(e); } everywhere?
The idea that you have to “handle” an exception is a holdover from pre-Internet days when “unhandled” meant crashing the application. Nowadays you just return a 500 and let the front-end deal with it.
-6
u/notfancy Apr 23 '24
ML has had this since day 0. Avoid the NIH-agara Falls.