4 ms·
> What if the Rust developer uses fork().unwrap_or(default_value) in a hurry The point here is that the language's tools and APIs can significantly better driv
by masklinn 11y ago
> What if the Rust developer uses fork().unwrap_or(default_value) in a hurry
The point here is that the language's tools and APIs can significantly better drive the developer towards the safe/right solution, that's a large point of type theory and static type systems after all. In this case rust's type system is used to split out the various "result cases" and notify the developer upfront of the various cases to handle. The return type pretty much tells you how the function will behave and what you need to take care of as the caller.
That aside, why would you unwrap_or(default_value) if you're in a hurry when unwrap() is shorter (and you can later grep for "unwrap()" to find dodgy/hurried code, whereas unwrap_or is a perfectly legitimate recovery strategy).
> Now, if you're about to tell me that the examples above are totally stupid and no developer would do such a thing, then you know how I feel about the sloppy C versions. Doing a system call and not checking for error is totally stupid as well.
The issue being that even though you have a compiled statically typed language it's of absolutely no help in "checking for error", and interactions between syscalls can be hard to predict, not checking for fork(2)'s error isn't the end of the world... until you pass its result to kill(2) for instance (it might also give strange results if you pass specific pids to waidpid)
- sickbeard 11y agoThis has been proven to be wrong over and over again with the many variations of languages that came after C. Newer "safer" languages don't improve bugs
- kod 11y agoWhere's this "proof" you speak of? By contrast, strong static typing does in fact prove the absence of certain errors.
- nickpsecurity 11y agoOn contrary, empirical studies done in the 90's and such by the likes of Mitre Inc showed people using Ada and C++ were more productive than C developers while producing way less defects. That the language and libraries were designed specifically to counter hard-to-track issues were one of the reasons why. That languages would improve safety was known far back as MULTICS with PL/0 where it's prefixed strings and reverse stack prevented two of the most common crashes/hacks in UNIX/C land. The evidence is on our side that well-design language significantly reduces number of defects in production code if other variables are equal.
- pcwalton 11y agoWhere are all the use-after-free bugs leading to remote code execution (for example) in projects written in languages other than C or C++?
- joehillen 11y agoThat is blatantly false. Type-safety can prove (as in a mathematical proof) that whole classes of bugs are impossible.