|
|
|
|
|
by ChadNauseam
1463 days ago
|
|
Yeah, but that doesn’t mean all languages are created equal in that department. Let’s take this pseudocode: int a = 0;
if (findindex(mylist, myvalue, &a)) {
// dostuff with a
}
Here, findindex returns false if it can’t find the value. The problem is that there’s nothing forcing you to use the if, you can just forget it and you’ll be left with incorrect code. In Rust, this type of error is impossible to make by accident, because the findindex function would return an Option, and you have to explicitly handle both cases (or explicitly say you don’t care about one of the cases).Things like that, along with the lifetime system, make it easier to write good code. It’s like saying that it’s possible to destroy your foot with a shotgun and with a pencil – it’s possible, but it’s a lot easier do to by accident with the shotgun. |
|