logoalt Hacker News

dabinat • yesterday at 10:01 PM • 3 replies • view on HN

One of the things that I think makes Rust unique is that it acknowledges the possibility of human error. I think it’s also one of the most controversial too: there are certain people who get an ego hit at the insinuation that they ever could have written C code with mistakes.

Instead of hoping you remember to check for NULL, Rust forces you to make a decision on how to handle the possibility of failure. Sure, you can still pick a bad decision (unwrap) but that is at least a specific decision and you can’t forget to do it.

You can take it even further with things like the newtype pattern. If you have lots of numeric IDs (project ID, user ID, etc) you can give them distinct types so you don’t mix them up.

So Rust taught me I can program defensively against my own brain, which sometimes gets tired or lazy or distracted.


Replies

PaulKeeble • yesterday at 10:12 PM

This was always the same thing that Unit tests were trying to bring, defend against your own errors and try to get the most quality out of the tools as possible. A lot of language progress has been exactly this over the years, from removing goto and introduction of for/if/while to constraining types and everything since. As an industry we could do with more of this mindset in general, just use everything we can to try and catch bugs earlier when they are cheaper to find and fix and avoid them happening at all.

➕ show 1 reply
ardit33 • yesterday at 10:16 PM

Null should not exist, and Optionals are an anoying workaround/hack to it. Old languages like Tcl eliminated it, (every object has an initial value, it is never null).

It creates an interesting problem, as sometimes you want to know the absence of value. Usually done with the empty "" string.

The other way to handle is that every Object is initiated (pointing) to an starter initial value. (prototype based languages).

➕ show 4 replies
slopinthebag • yesterday at 11:33 PM

yes i love rust because i acknowledge my own limitations as a programmer. compare that to c/zig devs handwaving away vulnerabilities as "skill issues", any serious engineering discipline eliminates the possibility of human error wherever possible.

fwiw john carmack agrees with me