• 1 Post
  • 28 Comments
Joined 11 months ago
cake
Cake day: August 2nd, 2023

help-circle

  • Using it in pipes looks cool. IMO the usage in writing git commit messages is actually not useful. Almost always you should be writing the why, not the what. Same thing for comments. Unless the code has a good reason to be written inscrutably e.g. for performance, write simple code and comment why you’re doing something as necessary. Which is not to say “the code comments itself”, but the “what” comments should be higher level at a function or file level



  • The collect’s in the middle aren’t necessary, neither is splitting by ": ". Here’s a simpler version

    fn main() {
        let text = "seeds: 79 14 55 13\nwhatever";
        let seeds: Vec<_> = text
            .lines()
            .next()
            .unwrap()
            .split_whitespace()
            .skip(1)
            .map(|x| x.parse::<u32>().unwrap())
            .collect();
        println!("seeds: {:?}", seeds);
    }
    

    It is simpler to bang out a [int(num) for num in text.splitlines()[0].split(' ')[1:]] in Python, but that just shows the happy path with no error handling, and does a bunch of allocations that the Rust version doesn’t. You can also get slightly fancier in the Rust version by collecting into a Result for more succinct error handling if you’d like.

    EDIT: Here’s also a version using anyhow for error handling, and the aforementioned Result collecting:

    use anyhow::{anyhow, Result};
    
    fn main() -> Result<()> {
        let text = "seeds: 79 14 55 13\nwhatever";
        let seeds: Vec<u32> = text
            .lines()
            .next()
            .ok_or(anyhow!("No first line!"))?
            .split_whitespace()
            .skip(1)
            .map(str::parse)
            .collect::<Result<_, _>>()?;
        println!("seeds: {:?}", seeds);
        Ok(())
    }
    







  • I think people will still find joy in it, just of a different sort. As an analogy, used to be that you had to program a computer with assembly language, and it was rather painstaking to do. There were some real wizards doing that sort of work, like in the Story of Mel. Nowadays though, we’ve got high-level languages with compilers that do all the grunt work of actually writing assembly for you. Some people still worry about assembly specifically, but the vast majority of programmers don’t. The joy is no longer in writing the absolute fastest bare metal assembly you can for most people, it’s in using the right algorithms to solve a problem. You can write a few lines in Python that would’ve taken someone weeks to write in assembly.

    Something relevant to note in the above is that smarter compilers eliminating the need for people to write assembly directly didn’t mean the end of programming as a profession. There’s been an explosion in programming jobs, exactly because each person can do so much more than they ever could before, opening up new possibilities that weren’t there with everyone writing assembly.

    Likewise, I suspect the scale will change here. I admit I’m not an artist, but wouldn’t it be cool to see your artistic vision across an entire game? You could create an entire virtual living breathing city on your own without having an army of artists working on the grunt work like the exact concrete texture. If you decide to tweak the feel of the art, you don’t have to spend weeks redoing all the grunt work. Alternatively, if you draw a landscape that you get just right, imagine being able to experience it by having the AI generate a virtual world for you to walk through based on it.











  • Here’s a recent HN thread about the objects: https://news.ycombinator.com/item?id=35937540

    Metalworker status symbol seems compelling, as it explains several facts about them, and the knitting angle could be a chicken vs egg situation. Either knitters found an existing and relatively common object to be useful for their needs, or knitting is older than we think and the need for these tools drove metalworkers to decide that a hard-to-make tool was a good status symbol. Or maybe it’s both/and, with both needs influencing each other. I can easily imagine some metalworking culture deciding that this hard-to-make tool is a good status symbol, and they eventually turn it into something that’s not actually useful for the original purpose, but works great to show off.