logoalt Hacker News

0127 • today at 5:53 PM • 4 replies • view on HN

IMO this is where languages like Rust shine. The design patterns built into the language for handling errors (Result) - force you to handle errors / function results with sentinels, null pointers, or errnos are so much more error prone than handling a Result<T,E> using a match statement.

crypt() returning `*` is insane especially since these kinds of sentinels are all over /etc/passwd


Replies

adrianN • today at 6:02 PM

I guess this is where the culture around rust shines. You can write crypt that returns a string in rust just fine, just like you can write crypt that returns a tagged union in C. Cultural differences and syntactic sugar change which version is idiomatic.

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.

➕ show 1 reply
spullara • today at 6:22 PM

always has amazed me that there was so much hate for java checked exceptions where handling errors ought to be the norm.

➕ show 5 replies
Lt_Riza_Hawkeye • today at 5:58 PM

It seems it used to return NULL, but they changed it for "convenience"