• 0 Posts
  • 277 Comments
Joined 1 year ago
cake
Cake day: June 21st, 2023

help-circle
  • If in PHP or JS I make a change, hit F5, and get an error, that’s not any better than the IDE already showing it beforehand.

    This is even worse because it can happen in prod without you ever triggering this case. For some projects, it doesn’t matter because the impact of a bug is small. For most, you put a subpar, buggy experience in front of your users, waste more time looking for the cause and debugging later with upset users, and at worst cause actual damages (depending on the project anyway).


  • You can’t create a subset of an enum directly, but splitting this up into multiple types works. You can have FunctionAError with errors that function can produce and a variant for your common errors, and FunctionBError which is similar:

    #[derive(Debug, Error)]
    enum MyErrorCommon {
        #[error("bad value ({0})")]
        MyErrorCommon(String),
    }
    
    #[derive(Debug, Error)]
    enum FunctionAError {
        #[error("error a")]
        MyErrorA,
        Common(#[from] MyErrorCommon),
    }
    
    // and same for FunctionBError
    

    The try operator (?) will automatically use From impls to convert errors for you as well. If a function returns a result containing MyErrorCommon in your function and you use ? on it, it gets converted to that function’s error type for you. thiserror generates the From impl for you if you use #[from].


  • TehPers@beehaw.orgtoProgramming@programming.devBaby unit tests
    link
    fedilink
    English
    arrow-up
    13
    arrow-down
    1
    ·
    5 days ago

    Types aren’t unit tests. Unit tests only test a discrete set of inputs and outputs for correctness, and can miss cases that aren’t tested for.

    In sound type systems, they are closer to formal verification. The compiler guarantees the properties you expect of the type hold.

    As for the rest of the article, do what works best for you in your projects, but if I need to work with you, I’m going to ask for types. I need to know what types the interface expects to receive. Names are not enough. Document them, use type hints, whatever, just put them somewhere because I’m not psychic and I don’t know what you thought about when writing the function.









  • You’re right. Once it settles into its niches and the hype dies down, it won’t be overhyped anymore because everyone will have moved on.

    I’ve been working with generative AI for years now and we still struggle to solve real world problems with it. It isn’t useless or anything. It’s way too unreliable, and this isn’t one of those things where time will solve it - it’s being used to solve problems that have no perfect solutions, like human interfacing and generating culturally-appropriate and visually-accurate images. I’d expect it to improve at those tasks over time, but the scope needs to drop from every problem humanity has ever faced to the problems that these models are good at solving.



  • Ironically, I had friends in school who had come from juvy. I guess you could say prision fed into school instead? I’d love to ask them their opinions on that statement though and see how similar to prison school really was.

    As far as I can tell, that person is just rage baiting. If they genuinely believe school is the same as prison, having visited one myself (not for myself), all I can say is they should actually visit one and see for themselves what a prison is actually like.



  • I’m not sure why I see people treating banning smartphones in class like child abuse or something. The only explanation I have is that it’s a cultural thing. Obviously, if used appropriately, a smartphone is a valuable tool, but this is only if they are used appropriately, which some students will do and some won’t (and this varies as well from school to school and class to class). Where I went to school, a significant number of students did not use them appropriately during class, so not allowing them made sense since they distracted from the lesson.

    So, why do I have so little confidence that they’ll be used properly? Some people are posting anecdotes about their time as teachers in this thread, so I’ll post one from the student’s perspective. Despite smartphones not being allowed in my classes in high school, people used them anyway. Why? The teachers wouldn’t notice, or some might just not say anything. I played the heck out of one mobile game with my friends in both of my history classes, and nothing ever happened. I knew people who’d be listening to music during class too, and completely ignore the lecture itself. Almost everyone with a phone out used it as a distraction from class, not as a tool to help them learn. Despite there being a rule against them, I’d estimate more than half of the people I went to school with used them during class anyway.

    So why didn’t the teachers enforce it more strictly? My guess is because it wasn’t safe. Many of my friends carried knives at school for self defense. There were a lot of violent students, ranging from fights in the hallway to students being part of a gang. To be clear, this wasn’t by any means the majority of the student body, but it wasn’t an insignificant portion of it either.

    The violence escalated dramatically after the 2016 election, where students (who were understandably upset about the result) got up and threatened all the white people in the school. I had graduated by then, but I knew people who had to barricade themselves in a room with a mob of angry knife-wielding students on the other side of the door. Many of the students in the room weren’t even old enough to vote. One teacher left the school because of all the threats she’d received.

    Also, not sure how common it is to have a “senior prank day” at other schools, but we had one every year. The “pranks” ranged from spray painting threats to teachers on the outside of the gym, to destroying school property. Once they had to put classes on pause while a company came out to replace the locks on all the doors since the “prank” was to destroy the locks so the doors couldn’t be opened.

    This school was pretty tame too, compared to some of the schools I’d heard stories of. One teacher I talked to at a different school had stories about all the times some student threatened her or pulled a gun out on her or whatever, and it honestly just sounded like hell.

    Anyway, I wouldn’t say I blame the kids for this behavior, and while I have strong opinions against feed-driven social media, I don’t think it was a major contributor to these behaviors (this was before social media was as big as it is now). I think it really comes down to parenting, whether the parents are just bad at raising kids, or they don’t have time or resources to properly raise their kids, or their kids have needs they don’t know how to (or refuse to) satisfy. Regardless, a teacher can only do so much, so rather than trying to correct behaviors in students at the risk of their own lives, I think a lot of them just put up with it for the sake of the students who do want to learn.

    So if the rule is going to be broken anyway, why have a rule against smartphones? It sets the expectation of students regarding smartphone usage, and gives teachers an opportunity to enforce that rule when they feel it’s appropriate (and safe) to do so.

    Edit: I should also add that I don’t think most schools are this violent. This school was exceptionally bad, but it wasn’t as uncommon as you might think to have a school this violent.


  • Anytime anyone mentions integrating an HTTP client into Rust’s std, all it takes is one good Python anecdote to shut that discussion right down.

    Having the standard library be stable and not try to add a bunch of support for changing standards is a long-term benefit to the language. Having “de-facto standard libs” with crates like url, http, etc ends up being better because they can evolve independently from the standard library, at the pace their respective domains evolve.

    Although, I suppose an argument could be made that url is unlikely to really evolve anymore.



  • Some thoughts on the comments on Discord:

    I can understand most of the arguments against Discord, and there are some problematic communies on it of course, but I’m not sure I understand how using Discord over an alternative puts someone more at risk of exposure to those communities. People are free to join and leave servers at will, so is the issue that these servers built around FOSS projects have toxic communities? If so, how would being on any other platform solve this?

    Speaking from experience, just about all the servers I’m in have some kind of “no politics” rule, a very inclusive “be nice” rule, and a pronoun selector. Maybe it’s just the servers I join, but hate speech gets people banned pretty quickly.

    Anyway, there are plenty of arguments that can be made about discoverability, lack of control, privacy, and the non-FOSS nature of the platform to justify its presence on that list.