• 10 Posts
  • 143 Comments
Joined 1 year ago
cake
Cake day: June 2nd, 2024

help-circle




  • bleistift2@sopuli.xyztoProgrammer Humor@lemmy.mlTrue crime
    link
    fedilink
    English
    arrow-up
    34
    ·
    1 month ago

    The logic is fine. If you rename the variable to isAdmin, it makes perfect sense. Either they are an admin, or they are not an admin, or the state is unknown (here expressed as null). If you want to throw another JS-ism at this, undefined could be assigned before the check has been made.

    I regularly use variables like this. If users is undefined, I haven’t fetched them yet. If they’re a list, then fetching is complete. If they’re null, then there was an error while fetching.





  • If that’s the only error mechanism, sure. Exceptions in most languages tend to be relatively expensive, though, and most have a cheaper idiomatic way of returning error codes; you’d want to use those if they’re available, right?

    I think not being able to get the current time from the system is very exceptional. And I think exceptional circumstances should act that way and not “look like” normal executions. To me, that means letting hell break loose, and not “silently” return a 1 instead of a 0.

    By similar reasoning, “Exceptions in most languages tend to be relatively expensive” is a very weak argument. We don’t expect this error-throwing code to execute a lot.












  • So you might need to try different file extensions.

    No, you don’t. The HTTP response header will tell you what type it is.

    I’m not sure what you’re talking about. You need to know the name of the file before you can download it.

    For instance, my lemmy client, says in its HTML that its favicon is <link id="favicon" rel="shortcut icon" type="image/x-icon" href="https://sopuli.xyz/pictrs/image/9c6eeb58-bf66-4a15-9537-0a822f3c4feb.png">. If I were to blindly download /favicon.ico, I’d naturally get a 404 page:

    $ curl https://sopuli.xyz/favicon.ico -i
    HTTP/2 404 
    # more data