this post was submitted on 28 Nov 2021
11 points (100.0% liked)
Rust Programming
8306 readers
12 users here now
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I think that's the parent's point: in C/C++ you don't have to deal with null. You can just pass it around and potentially start unintended/undefined behavior. While in Rust, it's a compile-time error if you don't unwrap the option somehow (eg.
if let Some(content) = optional_content
).So yes it's more concise and "beautiful", but you'll probably bite your own hand at some point playing this game
How is it more beautiful? You have to deal with null pointers when you want to use the pointer anyway, if you don't you will get a runtime error, or worse, your program will keep running in an unintended state.
yes, that was exactly my point. You can just use a pointer without checking it, which is aesthetically more pleasing, but will produce garbage :)