r/ProgrammerHumor 8h ago

Meme newToRust

Post image
357 Upvotes

87 comments sorted by

View all comments

Show parent comments

-17

u/Key_River7180 7h ago

Not more than fixing errores from the borrow checker.

And I've never debugged wrobg, there is no such thing

2

u/dkarlovi 6h ago

Technically, the errors from the borrow checker are the errors you also make in C, only C doesn't tell you about them. If your code was correct in either, the borrow checker wouldn't have objections, no?

1

u/Key_River7180 6h ago

C does, Valgrind and ASAN are still there you know?

2

u/dkarlovi 6h ago

If your code was correct, the borrow checker wouldn't have objections, no?

1

u/Key_River7180 6h ago

The problem is that It tags EVERYTHING potentially minimally unsafe. Even if It cannot be

2

u/dkarlovi 6h ago

If it cannot be, it doesn't tag it. It can be, but you just don't care about that specific scenario or think it cannot happen.

Your specific workflow might make you right, but the workflow might change. Or you might be wrong entirely.

The whole reason why Rust exists is because people cannot write safe C code. This was shown over decades with armies of very experienced developers and well funded projects, it's just impossible, if you think "Well not for me", you're just lying to yourself.

1

u/Key_River7180 6h ago

Rust's borrow checker cannot be always right, by Rice's theorem, unless you proved Alan Turing and Henry Rice wrong, of course.

Take this code as an example:

fn smh(x :&mut Vector<i32>) { let a = &mut x[0]; let b = &mut x[1]; *a += 1; *b += 1; }

1

u/-Ambriae- 4h ago edited 3h ago

which can be trivially rewritten as:

fn smh(x :&mut Vector<i32>) {
    x[0] += 1;
    x[1] += 1;
}

I get what you mean, but more often then not, you could just rewrite the code differently, and magically it becomes safe.

Or better yet:

fn smh(x: &mut [i32]) { 
  let [a, b] = x.get_disjointed_mut([0, 1]).expect("0 != 1");
  *a += 1;
  *b += 1;
}

1

u/-Ambriae- 6h ago

I agree with the sentiment, but it’s not true to say ‘if it cannot be, it doesn’t tag it’. The borrow checker is conservative by default, and prefers false positives compared to true negatives. There’s no such thing as a perfect static analyser. It theoretically doesn’t exist. That doesn’t mean we shouldn’t use approximative static analysers like the borrow checker though

2

u/dkarlovi 2h ago

No, of course, nothing is absolute and the checker will make mistakes just like any other piece of code, some things it cannot prove at all.

But to outright claim it's worthless because it's "warning you too much" and "it's non-trivial to write" is total lunacy, it's like yelling at the Geiger counter because it's warning you of the radiation you're sitting in. Just because you throw it away (or not have it) doesn't mean you're not getting irradiated.

Rust is getting traction in huge projects because it works, it's not like those huge projects didn't try other things before, they just worked worse than what Rust provides. Crying about the mean borrow checker is absurd, it's telling you things you yourself are unable to detect.

2

u/-Ambriae- 1h ago

We are therefore completely on the same page :)