Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>"Correct way is to check BEFORE you pop_back()"

Absolutely and this is exactly what I do. I always check the containers before removing elements.

>"In Rust, any number of invocation of pop() will not result in undefined behavior. You can ignore the value, or you can check it, but it doesn't expose you to UB just for slightly misusing a vector."

I do not understand "slightly misusing" part. I assume in Rust it would bomb if pop() returns "none" and you try for example add said "none" to some number.



Vec<T>::pop() and similar methods return an Option<T>, so it's a compile-time type error to just add a number to it directly.


> I assume in Rust it would bomb if pop()

That's the thing. It wouldn't. Worse you can do is make whole program panic, with well defined stack trace and message.

It will never return non-sense and pretend all is ok.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: