3 ms·
> Oh boy. I see bugs everywhere in C and why the borrow checker exists. Any examples that you could provide? I have been dealing with C/C++ for close to 30 yea
by kanbankaren 2y ago
> Oh boy. I see bugs everywhere in C and why the borrow checker exists.
Any examples that you could provide? I have been dealing with C/C++ for close to 30 years. Number of times I have shot myself with undefined/unspecified behavior is less than 5.
- dafelst 2y agoThe borrow checker isn't just about UB, it is mostly about memory safety. I'm sure you've seen plenty of use-after-frees/use-after-move/dangling pointer type things or null pointer derefs, or data races, etc etc. These are largely impossible to do in safe rust.
- jjnoakes 2y agoThe number of times you shot yourself in the foot that you know about. Some of those bullets just haven't landed yet. C and C++ give you very interesting foot-guns: sometimes they go off even when you don't touch them (compiler upgrade, dependencies changing, building on a new architecture, ...)
- tsimionescu 2y agoIn 30+ years of experience in C, you haven't used a free()d variable or written past the end of a buffer more than 5 times? If that's true, then you have more care and attention than 99.99% of all C experts.
- kanbankaren 2y agoI should have been clear. Of course, I have done such mistakes, but they were caught early in the dev. process. I am talking about bugs that were caught in production due to misunderstanding of C compilers on 16/32 bit processors. I also avoid idioms like *p instead write p[i] whereever possible.
- oneshtein 2y agoBorrow checker checks memory safety. Undefined/unspecified behavior still present in Rust[1]. [1]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html https://doc.rust-lang.org/reference/behavior-considered-unde...
- bombela 2y agoOnly from code annotated unsafe. In other words, if you do not use the keyword unsafe, you have no undefined behaviors.
- eddd-ddde 2y agoClearly you must be superhuman then, something as simple as forgetting a null pointer check is bound to hit you every now and then.
- kanbankaren 2y agoOf course, I do, but they are caught early in the dev. process. Not in production though.
- kstrauser 2y agoI would contend that’s an unusually sophisticated dev process not used by most.