News for hackers. Stuff that matters.
Re:Reflections on Rust, and the Sand Castle Metaphor by v_lisivka on Friday April 27, 2018 @01:45PM (#16942698)
You need to type your Python code extremely fast to finish it 10 times faster than this Rust program:

    extern crate xpath_reader;
    extern crate regex;
    
    use std::io::prelude::*;
    use std::fs::File;
    
    use xpath_reader::Reader;
    use regex::Regex;
    
    fn main() {
      let mut contents = String::new();
      File::open("test.xml").expect("Unable to open the file").read_to_string(&mut contents).expect("Unable to read the file");
      //println!("File contents: {}", contents);
    
      let reader = Reader::from_str(&contents, None).expect("Cannot parse XML file");
      let files: Vec<String> = reader.read("//file").expect("Cannot find file entries in XML file");
      //println!("Files: {:?}", files);
    
      for file in files.iter() {
        println!("File: {}", file);
        let mut contents = String::new();
        File::open(file).expect("Unable to open the file").read_to_string(&mut contents).expect("Unable to read the file");
        //println!("File contents: {}", contents);
    
        let re = Regex::new(r"foo bar").expect("Cannot compile regex");
        let replaced = re.replace_all(&contents, "baz").to_string();
        //println!("File contents: {}", replaced);
    
        File::create(file).expect("Unable to overwrite the file").write(replaced.as_bytes()).expect("Unable to write to file");
      }
    }
Re:Reflections on Rust, and the Sand Castle Metaphor by cortesoft on Friday April 27, 2018 @11:02PM (#16945866)
This is a really silly counterpoint. I am not even sure what point you are trying to make. How can pasting some program show how long it would take someone to reason out how to write it?
Re:Reflections on Rust, and the Sand Castle Metaphor by IshKebab on Friday April 27, 2018 @05:09PM (#16944349)
It was rather more complicated than that. I could go into details but that's not really the point.

It's not the typing that is slow - it's the constant "why can't I do it like this?" stackoverflow trips. For example - how do you open a file in read-write mode? Using File::open()? Nope!

Ok that one is just poor API design - most of the time was really in restructuring to make the borrow checker happy, and fiddling with adding and removing '&' and 'ref' to get the right types.