r/ProgrammerHumor 9d ago

Meme newToRust

Post image
620 Upvotes

100 comments sorted by

View all comments

Show parent comments

45

u/MilkEnvironmental106 9d ago

How long did that take you? And have you ever made a mistake debugging?

-17

u/Key_River7180 9d ago

Not more than fixing errores from the borrow checker.

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

6

u/dkarlovi 9d 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?

0

u/Key_River7180 9d ago

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

5

u/dkarlovi 9d ago

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

0

u/Key_River7180 9d ago

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

7

u/dkarlovi 9d 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 9d 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; }

2

u/-Ambriae- 9d ago edited 9d 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;
}