• 38 Posts
  • 1.48K Comments
Joined 6 years ago
cake
Cake day: May 31st, 2020

help-circle


  • Had to just think about why #[non_exhaustive] exists, so perhaps this helps you as well:

    Imagine you’re developing a really important core library, something like TCP. And then other libraries depend on your library.
    Now, if you change your implementation, you may need to introduce a new error case, even though the rest of the API still works the same.

    You have two choices to deal with that:

    • Release version 2.0, because that’s a breaking change. Each library that depends on you needs to manually upgrade to version 2.0. Some never will, because they’re unmaintained. Any application that ships your library as a transitive dependency will need to ship both, version 1.0 and version 2.0, for the next few years until the last of their direct dependencies has upgraded to 2.0 or been removed.
    • Or: You’ve declared that error enum #[non_exhaustive] before going 1.0 and therefore forced all depending libraries to implement a default match case. You can sneak in the new error case in version 1.1 without all those depending libraries needing to manually upgrade. The ecosystem does not split in half between 1.0 vs. 2.0.

    Obviously, if it’s a really egregious new error case that needs specific handling, then you might still want to release version 2.0, but by adding the #[non_exhaustive], you can decide later on and if you are such a central library, there’s definitely going to be situations where you want to make use of it.







  • Well, they would typically have a system prompt (like an invisible chat message that’s sent to the LLM at the start of the conversation), where it would tell the LLM something like “You’re a helpful chatbot. Talk cheerfully and use 🩵 all the time.”

    And in that system prompt, you can also give it instructions to only answer certain questions. But it really is like a chat message, in that it just as well might ignore those instructions when another chat message asks it to.

    OP chose the formulation “Before I subscribe to a creator, …” which might be necessary here to get it to answer, as it might have been told to only help with creator subscriptions, but then the formulation implies that by answering this question, it is helping the user to subscribe. That’s called a prompt injection.

    If you can find a prompt injection, then yes, you can do this with any chatbot.
    Although they might still not be as useful as a dedicated tool, since they likely can’t do tool calls, like web searches or running the compiler.





  • Yeah, not a bad stance to have. When I switched to Linux (in the middle of a compsci minor), I thought I was the king of the world and that I knew everything about computers.

    Then Linux showed me that I know fuckall, not because it was particularly hard, but rather because it’s an open library.
    You can look at a random config file on your PC and it will explain you highly technical concepts for free.
    You can look at the source code of anything you’re interested in. Well, or probably rather read an explainer from someone who read/wrote the source code.
    And you can easily look at the logs of your applications to debug them.

    Every so often, I run into folks that genuinely seem to know a lot about Windows, and I always wonder how. It doesn’t explain anything to you. 😅








  • Small nitpick that I noticed while skimming the code:

    Where you define your constants, you can change those comments to be doc-comments instead, so that your editor can display them when you hover over constants.

    And personally, I would go one step further with the units, by putting them at the end of the name of the constant, like you did with some variables in the code. That way, the unit shows up inline while reading code that uses the constant, which makes it easy to see that units match up (or not).

    Side-note: You don’t have to denote the unit for Duration. You construct it from milliseconds, but then it’s unitless and you decide where you use it in what unit you want the value. So, Duration is very cool and I would recommend using it for LRC_START_THRESHOLD as well.

    But yeah, back to the comments-thing: Plain comments are kind of inherently crappy, because they only show up in one place in the code, so you’re less likely to see them and less likely to update them. By putting things into doc-comments, names, log statements, error messages etc., they show up in at least two places.
    Plain comments only really make sense for explaining why the code does something. The what can generally be explained in other ways, at least in a sufficiently abstracted language like Rust.