4 ms·
Java Language Update – a look at where the language is going by Brian Goetz
- MrBuddyCasino 2y agoThe hypothetical return type for Future using ADTs was interesting - this seems almost Rust-ish. The distinction between a return Value and an Exception really is often unnecessary and complicates things.
- jayceedenton 2y agoI struggle with this one because exceptions are a perfectly good solution. The compiler will tell you when you are not handling a failure case. And if exceptions are unchecked, then you won't get a compiler warning but at least failures will be obvious at runtime. Why push java towards this 'failures as return values' when we already have a solution? Yes, you will be able to get the compile-time safety by immediately using switch on the return value, but what if you don't? Exceptions are a completely sound solution, failures as return values can easily escape detection. No-one likes having to think about the error cases, it feels like it complicates things. But we need to stop seeing exceptions/try/catch as something to eliminate and realise that this approach is one of the best innovations of Java. Using return values, or monadic approaches to error handling, are fundamentally unsafe when you have a mixed paradigm language. Far too easy for the programmer to do something wrong, so we're relying on discipline again and not the compiler. In other words, back to square one.
- gergo_barany 2y ago> Yes, you will be able to get the compile-time safety by immediately using switch on the return value, but what if you don't? Then you switch on the value at some other point in time. It's still AsyncReturn<V>. Why do you think safety would get lost? > Exceptions are a completely sound solution, failures as return values can easily escape detection. How so?
- MrBuddyCasino 2y agoWell you can ignore return values (Rust & Golang force handling them) in Java, exceptions are „unstoppable“ by default.
- potatochup 2y agoRust has lints for unused result types, but I've still seen new coders unintentionally write let _ = failable_call(); Which suppresses the error entirely. I wouldn't say it's "easy", and it hasn't really been a problem in production. But maybe this is where the parent post is going.
- gergo_barany 2y agoI see. Yes, deliberately ignoring the result and error might be a problem. Of course the same novice programmers could write: try { failableCall(); } catch (Throwable t) { /* Ignore. Stupid Java, always forcing me to handle checked exceptions that won't happen in practice. */ } In general, I'd say the choice between exceptions and a result-or-error return type should be driven by how likely the user of the method is interested in the return value. In the specific context of this discussion, there is no reason to call a future's get method unless you're really very interested in what it returns. So in this case I'd think the result type would be a good choice. For other APIs the trade-off is different.
- tpoacher 2y agoI'd say between a stupid result out of ignorance or risky defaults, vs a stupid result out of explicitly being stupid and overriding sane defaults, the latter is probably safer. Also, exceptions (particularly checked ones) are not a simple matter of optional checks; they form an explicit contract forcing you to deal with exceptions (and having to be explicitly stupid to make them useless via an empty try/catch block). Compare to type-contracts where you'd need to go out of your way to make the "Null" part of the union type "useful" in the first place, for example.
- deleted 2y ago[deleted]
- juliangamble 2y ago21:48 the reasoning is facinating. "OOP thrived in an age of monoliths. But program units are getting smaller. They don't need as many internal boundaries. They are often coupled by less strongly typed schema."
- DarkNova6 2y agoI think you are misrepresengin Goetz slightly. He said "OOP was necessary in the time of Monoliths because they erect clear boundaries".
- lolinder 2y agoI haven't had a chance to listen, but if he said those exact words they certainly seem to imply the rest of what OP said. EDIT: I have now listened, and I'm with OP on their interpretation. Goetz doesn't say the exact words that OP used, but he definitely expresses each idea and means what OP says he means.
- symaxian 2y agoI understand where he's coming from, but on the other hand it sounds like he's trying to avoid saying "maybe that OOP thing isn't all it was cracked up to be".
- Pet_Ant 2y agoI think that is more descriptive and less prescriptive. I’ve never seen a codebase ever really use OOP in an enterprise setting. Just spaghetti and meatballs architecture. Meaty god objects “services” with long strings of structs.
- sirwhinesalot 2y ago"You just didn't do OOP right." Everytime.
- 2y ago
- rlawson 2y agoI don't like Oracle very much but I have to say I appreciate the rate at which Java has improved
- rcaught 2y agoAppreciate Kotlin and others pushing it there.
- kaba0 2y agoYeah, the ant pushing the elephant..
- marginalia_nu 2y agoJava's stated design philosophy since way back is to let other languages experiment and then incorporate what appears to work out, thus being able to maintain an append-only change philosophy where everything is always backwards compatible. Kotlin is undeniably a source of inspiration, as is many other languages. (This doesn't always work out, some bad API decisions[1] will likely haunt Java forever, some features are arguably a bit undercooked (e.g. exception handling in Stream:s), but given the constraints it's kind of remarkable how well it does work) [1] https://stackoverflow.com/questions/21410683/boolean-getbooleantrue-returns-false https://stackoverflow.com/questions/21410683/boolean-getbool...
- kaba0 2y agoThat’s true. But why would Java take inspiration from Kotlin, which adds very little new to the picture (scala has done basically everything before, let alone ML, from where most of the new features java (or any other modern language) copies originate from)
- deleted 2y ago[deleted]
- vbezhenar 2y ago