AernaLingus [any]

  • 0 Posts
  • 14 Comments
Joined 3 years ago
cake
Cake day: May 6th, 2022

help-circle

  • I’ll preface this by saying I’m working my way through the Rust book, too–just a bit further along–so don’t take my word as gospel.

    This exact scenario is what the ? operator was designed for: returning early with the Err if one is received[1], otherwise unpacking the Ok. As you’ve discovered, it’s a common pattern, so using the ? operator greatly cuts down on the boilerplate code. If you wanted to do the equivalent of you have here (panicking instead of returning the Err for it to potentially be handled in calling code, albeit without your custom panic messages[2]) you could achieve this with unwrap() instead of ?:

    let html_content_text = reqwest::blocking::get(&permalink).unwrap().text().unwrap();
    

    Both of these will be covered in chapter 9.

    If you want to avoid those constructs until later, the only thing I’d say is that some of the intermediate variables seem unnecessary since you can match on the function call directly:

    fn get_document(permalink: String) -> Html {
            let html_content = match reqwest::blocking::get(&permalink) {
                Ok(response) => response,
                Err(error) => panic!("There was an error making the request: {:?}", error),
            };
    
            let html_content_text = match html_content.text() {
                Ok(text) => text,
                Err(error) =>
                    panic!(
                        "There was an error getting the html text from the content of response: :{:?}",
                        error
                    ),
            };
    
            let document = Html::parse_document(&html_content_text);
    
            document
        }
    

    You could also eliminate the final let statement and just stick the parse_document call at the end, but that’s a matter of preference–I know having an intermediate variable before a return can sometimes make debugging easier.

    As for whether you should build something now or wait till you learn more–go with your gut! The most important thing is that you stay actively engaged with the material, and many people find diving into projects as soon as possible helps them learn and stay motivated. You could also use rustlings and/or Rust by Example as you go through the book, which is what I’ve been doing (specifically rustlings). It’s not as stimulating as writing a project from scratch, but it does let you write some relevant code. And if you’re not already, I highly recommend using the Brown version of the Rust Book which includes interactive quizzes sprinkled throughout. I’ve found them particularly helpful for understanding the quirks of the borrow checker, which is a topic it continues to revist throughout the book.


    1. There’s also some type coercion, but that’s beyond the scope of your question ↩︎

    2. edit: you can use expect to get the custom messages as covered in another comment–not sure how I forgot that ↩︎


  • Facebook (when that was still a platform young people used). I would obsessively scroll through it for hours each day, basically trying to look at and comment on EVERYTHING. On a whim, I decided to take a break from it for a month. By the time the month was up, I realized I didn’t miss it at all, and that was that. One of the big takeaways was that I thought that I was forming relationships with the people I’d comment back and forth with, but in reality these were people who I would never hang out with outside of school and barely even talk with in school (if at all); it was all just superficial, and I was better off spending time talking to my actual friends.

    It wasn’t that bad, but in high school I mindlessly got into the habit of drinking a few cups of Coke each day (I think it started because I would get a 2 liter whenever I’d order pizza). I quit it pretty much cold turkey, and not only did I stop drinking it at home, I no longer order it at restaurants either, which is something I did ever since I was a little kid. The idea of just buying a bottle of soda and drinking it is straight honestly grosses me out now even though getting a can or bottle from a vending machine was something I’d do without thinking. The one exception is when I’m pigging out at the movies with a bucket of popcorn, but that’s pretty rare.










  • There’s a variable that contains the number of cores (called cpus) which is hardcoded to max out at 8, but it doesn’t mean that cores aren’t utilized beyond 8 cores–it just means that the scheduling scaling factor will not change in either the linear or logarithmic case once you go above that number:

    code snippet
    /*
     * Increase the granularity value when there are more CPUs,
     * because with more CPUs the 'effective latency' as visible
     * to users decreases. But the relationship is not linear,
     * so pick a second-best guess by going with the log2 of the
     * number of CPUs.
     *
     * This idea comes from the SD scheduler of Con Kolivas:
     */
    static unsigned int get_update_sysctl_factor(void)
    {
    	unsigned int cpus = min_t(unsigned int, num_online_cpus(), 8);
    	unsigned int factor;
    
    	switch (sysctl_sched_tunable_scaling) {
    	case SCHED_TUNABLESCALING_NONE:
    		factor = 1;
    		break;
    	case SCHED_TUNABLESCALING_LINEAR:
    		factor = cpus;
    		break;
    	case SCHED_TUNABLESCALING_LOG:
    	default:
    		factor = 1 + ilog2(cpus);
    		break;
    	}
    
    	return factor;
    }
    

    The core claim is this:

    It’s problematic that the kernel was hardcoded to a maximum of 8 cores (scaling factor of 4). It can’t be good to reschedule hundreds of tasks every few milliseconds, maybe on a different core, maybe on a different die. It can’t be good for performance and cache locality.

    On this point, I have no idea (hope someone more knowledgeable will weigh in). But I’d say the headline is misleading at best.



  • MartSnack - okay, this one is kind of cheating because there’s only one video so far, but if you like obscure and highly technical video game challenges like the SM64 A Button Challenge, it’s one of the best damn videos on the internet right up there with pannenkoek’s classic Watch for Rolling Rocks - 0.5x A Presses. It’s satisfying, interesting, and also surprisingly funny and relaxing. I’ve watched it like 7 or 8 times by this point, and I’m gonna watch it again after I submit this comment. Also if you like it def subscribe and hit the bell, he’s been working on a new video for months and has been giving updates in the comments as recently as a few days ago, so hopefully it’ll come out eventually!

    Church of Kondo - Repository for remastered video game OSTs (primarily the cartridge era). These aren’t just any old remastered, but the result of countless hours of painstaking research to identify the exact samples used in games, track them down in the highest possible quality, and recreate a “perfect quality” mix. They’ve got reams of spreadsheets detailing all the samples they’ve cataloged.

    mklachu - Dope Otamatone covers with extremely cute Otamatone costumes

    Retro Game Mechanics Explained - Probably the highest production value you’ll ever see for videos on this topic–combines a deep knowledge of retro game hardware and programming with beautiful visualizations and demos. His video on Pac-Man ghost behavior is pretty representative of how he takes a subject and drills down to the assembly to show you exactly what’s happening with some really cool graphics that show what the code does step by step.


  • Holy shit. I’ll be honest, having quit using reddit for daily browsing and simply relegating it to its main productive purpose of “usable Google results,” I kind of assumed that the outrage over the API pricing ultimately didn’t have much of an effect. But this data is nuts. I guess it goes to show the effect that alienating power users can have on a site that’s so power-user driven, where a fraction of users even comment and a tiny fraction of that fraction posts content and an even tinier fraction of that tiny fraction moderates to keep things running smoothly.