News for hackers. Stuff that matters.
Re:A Little Story About the `yes` Unix Command by agwa on Wednesday October 11, 2017 @08:41PM (#15454793)
The main function is egregiously overcomplicated.

This is how I'd write it instead:

  fn main() {
        match env::args_os().nth(1) {
                None => write(b"y\n"),
                Some(arg) => {
                        let mut arg = to_bytes(arg);
                        arg.push(b'\n');
                        write(&arg);
                }
        }
        process::exit(1);
  }
It's just as efficient and far more readable. It avoids Cow, a lambda, and the chain of combinators.
Re:A Little Story About the `yes` Unix Command by sinistersnare on Wednesday October 11, 2017 @09:05PM (#15454896)
Doesn't this only print once, and not over and over, like `yes` should?
Re:A Little Story About the `yes` Unix Command by agwa on Wednesday October 11, 2017 @09:15PM (#15454940)
The write function takes care of repeating it. See the complete source code in the blog post.