3 ms·
> Even Rust, which has probably come closest to a genuine solution Haskell Maybe Scala Option Java Optional These things have existed for over a decade (mul
by paulddraper 2y ago
> Even Rust, which has probably come closest to a genuine solution
Haskell Maybe
Scala Option
Java Optional
These things have existed for over a decade (multiple, in the case of Haskell).
- crest 2y agoAll of these didn't just give you something equivalent to C malloc()/free() with a parameter and result type. Maybe monads are useful in a lot of cases, but require a safe type system that prevents accidentally/negligently ignoring errors and language features to make it easy to unwrap the enum variants e.g. destructuring pattern matches and a collections of functions to work with them. I know both Rust and Haskell have those and suspect the other two examples as well. Without them they would be a pain in the ass to use.
- alpinisme 2y agoI think that’s the point though. This is an area where C just isn’t expressive enough and other languages have come in with a solution to fix that.
- ajross 2y agoThe question isn't the ability to handle errors, though. You can do it trivially in C too. It's whether or not the design chosen to permit that has benefits that outweigh its costs. And as I said I think the jury is very much still out on that one. Again, we tried to do this with exceptions in the early 90's and whiffed badly. Doing it at the validation/assertion/fuzzing/coverage layer with instrumentation tools turns out to be really effective in practice but the uptake remains really low. Today the mindscape points to Rust's Option as the saviour, which is why I listed it. But as you point out, all these other environments had it much earlier. And... kinda failed. So I'm not hopeful. In-band sentinels like NULLs and error codes are (1) clear and obvious, (2) near-zero-overhead and (3) extremely useful. Everything else falls down on at least one of those requirements.
- paulddraper 2y ago> And... kinda failed. Huh? I suppose maybe the Java one is dubious(?), but the others were very happily adopted by the ecosystem over sentinel values.