crypt() returning `*` is insane especially since these kinds of sentinels are all over /etc/passwd
[–] adrianN 3 days ago
[–] mort96 3 days ago
[–] asveikau 2 days ago
One is to return NULL for errors.
Another is to make the string result a parameter and use a return code to signal error.
A third, less common but still out there, is an error parameter.
Failure to observe these is on the caller. Forcing the caller to consider the error is probably where rust shines.
But a good C programmer is thinking about these idioms when they encounter a function signature for the first time, or they write one.
[–] mahboi 2 days ago
[–] dabinat 2 days ago
[–] mahboi 2 days ago
[–] spullara 3 days ago
[–] sieve 2 days ago
h = file_open(path)
data = file_read(h)
file_close(h)
return data
is the code you want to read. This essentially is: return file_open(path).success(h -> h, file_read(h)).success(h, data -> file_close(h); data)
A language with thoughtful error handling primitives will support such code.[–] zmmmmm 2 days ago
This is the root of a lot of the evil. Yes, humans want to program for the happy path. It is a lot more fun. However, that bias leads to so much lack of diligence to properly deal with the unhappy path.
[–] sieve 2 days ago
You ideally want to attack the problem at two ends:
- make the syntax noise-free so you can see what is happening
- build primitives at the syscall and stdlib level for common footguns
You would still need to deal with domain-specific logic errors, but you have at least reduced the surface area exposed to casual attacks.
[–] groestl 2 days ago
It is not. Being extremely restrictive in the happy path, throwing all over the place, but have generic error handling code at the top level (e.g. HTTP entry point) makes for some pretty robust, stable, easy to read software. Albeit it typically has somewhat rough user experience.
The thing is, that's a pretty good place to start. From there on, you can handle exceptions one by one, surgically, and make things nicer.
[–] mahboi 2 days ago
[–] mahboi 2 days ago
[–] spullara 2 days ago
[–] sieve 2 days ago
[–] spullara 2 days ago
[–] sieve 2 days ago
I do prefer Maybe/Option/Either style returns in some cases though. Makes for a cleaner API.
So each method has its uses.
[–] mahboi 2 days ago
[–] pandemic_region 2 days ago
[–] pie_flavor 2 days ago
[–] groestl 3 days ago
[–] drdec 2 days ago
Which is why exceptions in Java can bubble up the stack? You don't have to catch it in a particular method you can let it go to the caller of the method, and so on.
[–] mahboi 2 days ago
[–] spullara 2 days ago
[–] mahboi 2 days ago
[–] groestl 2 days ago
[–] 0x457 2 days ago
Rust makes handling and mapping `Result` locally more ergonomic, even though `?` makes propagation easy too. Rust, however, also makes it easy to lose the context during propagation and end up with useless `Error`.
[–] kaoD 3 days ago
Right idea at the wrong time.
[–] zmmmmm 2 days ago
[–] javier2 3 days ago
[–] cloverich 2 days ago
Having been on the receiving end of debugging that a few times, I no longer mind the in-band error handling, although admittedly I'm inexperienced enough to be confident its better. Just for the random code I've had to read where I just need to know exactly how something I didn't write and will never read again works, and whether the error is handled and how, i love reading in-band error handling, even if I too dislike the way an error laden routine must be written. Over time I've come to appreciate elegance "in the large" as opposed to the code I see in any individual function.
[–] _flux 2 days ago
I have written very little Java, though, so this is more of an armchair analyst position.
[–] Terr_ 2 days ago
The same way that layered code should react/wrap/translate when it comes to return types, it should do the same for thrown exceptions, and checked-exceptions helps you do that. They're both results of computation.
[–] creatonez 2 days ago
[–] Lt_Riza_Hawkeye 3 days ago
[–] mahboi 2 days ago
[–] lakeviewterrace 2 days ago
Another Rust self-suck session rendered completely irrelevant. Again.
I suppose if people started writing lots of code that crashed on error in Rust some enterprising developer might improve the function to always return a non-error value and set it to ‘*’ in error cases.