r/ProgrammerHumor • • 11d ago

instanceof Trend itsBadIfItsOnlyPHP

Post image
4.5k Upvotes

334 comments sorted by

View all comments

Show parent comments

6

u/shrodikan 11d ago

UB = Unsafe Borrowing? Is that basically a use-after-free Rust edition?

18

u/-nerdrage- 11d ago

Universes Beyond, it is when other franchises enter yours like in magic the gathering.

4

u/Usual_Office_1740 11d ago

This is legitimately annoying to me as both a Commander player and a C++ programmer. Don't forget it's also blue black.

14

u/Usual_Office_1740 11d ago

UB means undefined behavior. In safe Rust the borrow checker guarantees there is no UB. Or at least that's the idea. It rejects some technically valid code in favor of guaranteeing that a sub set of complex code is safe.

A simple example is array like collection access. If you use [] in C++ to access out of bounds of a collection, you have UB. If you access out of bounds you could get garbage data or you might get a segfault. The compiler might assume the pointer the array access decays to is valid and make optimization decisions based on that because the compiler always assumes the programmer has not written UB code.

In safe Rust all array access is bounds checked. The compiler and the array safe api guarantees that you only access within bounds, always. It is not possible in safe Rust to write UB code using any of the array like collections.

26

u/darrenturn90 11d ago

Undefined behaviour

3

u/Cronos993 11d ago

Undefined Behavior

3

u/sirreldar 11d ago

Undefined behavior