Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

rust just got 4x more productive [shill thread]

Name: Anonymous 2016-12-16 15:09

Rust designers developed an idiom for concisely propagating errors outwards with a macro called try!:
let file = try!(File::open("file.txt"));
More recently, Rust shipped an even more concise notation for error propagation, the postfix ? operator:
let file = File::open("file.txt")?;

Name: Anonymous 2017-01-01 9:58

>>26
A lot situations only work with nullable pointers
Wrong. Here is the next from Rust's iterators:

fn next(&mut self) -> Option<Self::Item>;

See how it returns an Option instead of just Item? It forces you to handle the end of list case, but it also prevents you from checking more than once:

match result {
Some(x) => ..., // In this branch you can be sure that x is an item and not some NULL bullshit.
None => ..., // In this branch you have to handle the end of list/none/NULL case, the compiler will complain if you don't.
}


And you can already emulate non-nullable pointers in C++ with references.
Orly? I'm not a C++ expert but it seems that Sepples references, while being genuine references unlike in Java/C#, are still pretty limited:

http://www.geeksforgeeks.org/references-in-c/
Due to the above limitations, references in C++ cannot be used for implementing data structures like Linked List, Tree, etc.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List