AernaLingus [any]

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

help-circle

  • I feel like there’s not much to fight about. I can understand the latter perspective, but from a practical point of view it just makes sense to consistently assign it to AM/PM rather than creating an unnecessary edge case (lord knows there are enough of those with date/time systems). Also this is all made moot by the superior system: the 24-hour clock (now THERE’S something I bet you could have a good argument about!).


  • I can’t remember the specifics (both because it was dumb and because it’s so embarrassing I think my brain is trying to protect me), but from what I recall I got into a heated argument on the internet with someone because I felt that fans weren’t cheering hard enough for a band I liked at a concert.

    …yeah, I know. I’m grateful, though, because it was so colossally stupid and pointless that I had a come-to-Jesus moment and swore off internet arguments entirely. I can only imagine the countless hours of my life it’s saved me in the intervening years.





  • 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 ↩︎




  • AernaLingus [any]@hexbear.nettoScience Memes@mander.xyzPoop Knife
    link
    fedilink
    English
    arrow-up
    19
    ·
    edit-2
    6 months ago

    Davis states that the original source of the tale was Olayuk Narqitarvik. It was allegedly Olayuk’s grandfather in the 1950s who refused to go to the settlements and thus fashioned a knife from his own feces to facilitate his escape by skinning and disarticulating a dog. Davis has admitted that the story could be “apocryphal”, and that initially he thought the Inuit who told him this story was “pulling his leg”.

    That’s a long payoff for a practical joke, but totally worth it.

    Also, unsurprisingly, they won the 2020 Ig Nobel Prize in Materials Science (lol) for this one (video of the ceremony, Ig Nobel “lecture” from the lead author (also the primary pooper))



  • 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.