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

C vs Rust

Name: Anonymous 2015-02-13 1:07

C:
int main(int argc, char **argv) {
int r;
if(argc > 1) {
r = atoi(argv[1]);
} else {
usage();
exit(EXIT_FAILURE);
}
}


Rust:
fn main() {
let argv: Vec<Result<String,OsString>> = std::env::args()
.map(|x| x.into_string())
.collect();

let r = match argv.get(1) {
Some(x) => match x.parse::<i32>() {
Ok(v) => v,
Err(_) => {
show_usage();
panic!()
},
},
None => {
show_usage();
panic!()
}
}
}


Type explosion is to be expected. Do notation could have been used to keep the control logic as clean as C, but Rust is not HASKAL and never will be anything like HASKAL and you're an asshole for wanting to write readable code you filthy shit fuck.

Name: Anonymous 2015-02-23 14:55

You do not need to annotate most types; I can't tell if this is b8 or you are actually this ignorant, because you are misrepresenting idiomatic rust with extreme prejudice. Just because you have not learned the language yet does not mean you can bash on it (in fact, quite the opposite…)

#![feature(env)]

use std::env::{args, set_exit_status};

fn main() {
let r = match args().nth(1) {
Some(a) => a.parse::<i32>().unwrap_or(0),
None => {
show_usage();
set_exit_status(1);
return;
},
};
}

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