Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

agnos.is Forums

  1. Home
  2. Programmer Humor
  3. True crime

True crime

Scheduled Pinned Locked Moved Programmer Humor
programmerhumor
71 Posts 33 Posters 2 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S [email protected]

    I was thinking of the three legal states as:

    • not logged in (null or {isAdmin: false, isLoggedIn: false})
    • logged in as non-admin (false or {isAdmin: false, isLoggedIn: true})
    • logged in as admin (true or {isAdmin: true, isLoggedIn: true})

    which leaves {isAdmin: true, isLoggedIn: false} as an invalid, nonsensical state. (How would you know the user's an admin if they're not logged in?) Of course, in a different context, all four states could potentially be distinctly meaningful.

    C This user is from outside of this forum
    C This user is from outside of this forum
    [email protected]
    wrote last edited by
    #46

    Honestly logged in is state and shouldn't be on the user object.

    1 Reply Last reply
    0
    • S [email protected]

      a === b returns true if a and b have the same type and are considered equal, and false otherwise. If a is null and b is a boolean, it will simply return false.

      U This user is from outside of this forum
      U This user is from outside of this forum
      [email protected]
      wrote last edited by
      #47

      I see, so logically it is fine.
      Just not in the context.

      1 Reply Last reply
      0
      • S [email protected]

        My preferred way of modelling this would probably be something like
        role: "admin" | "regular" | "logged-out"
        or
        type Role = "admin" | "regular";
        role: Role | null
        depending on whether being logged out is a state on the same level as being a logged-in (non-)admin. In a language like Rust,
        enum Role {Admin, Regular}
        instead of just using strings.

        I wouldn't consider performance here unless it clearly mattered, certainly not enough to use
        role: number,
        which is just about the least type-safe solution possible. Perhaps
        role: typeof ADMIN | typeof REGULAR | typeof LOGGED_OUT
        with appropriately defined constants might be okay, though.

        Disclaimer: neither a professional programmer nor someone who regularly writes TypeScript as of now.

        O This user is from outside of this forum
        O This user is from outside of this forum
        [email protected]
        wrote last edited by [email protected]
        #48

        Yeah obviously with constants for the set roles per value. Some languages call them enums, but the point is that what we pass and use is always still the smallest integer type possible. With the extra bonus that if the roles ever become composable, the same value type would likely suffice for a bitflag and only thing needing refactoring would be bitshifting the constants.

        But anyway, this turns out to be the weirdest hill I find myself willing to die on.

        1 Reply Last reply
        0
        • D [email protected]

          Depends on your requirements.

          If the admin status needs to be checked in a database, but most actions don't require authentication at all, it's pointless to waste resources checking and it would be left null until the first action that needs the information checks it and fills it in as true or false.

          O This user is from outside of this forum
          O This user is from outside of this forum
          [email protected]
          wrote last edited by
          #49

          I don’t really follow you there, wouldn’t it be exactly the opposite and wouldn’t checking for nulls be, as a premise, more wasteful? But doesn’t really matter, time to digress. I’m conventionally educated as an engineer so what I know and find reasonable today might be outdated and too strict for most contemporary stuff.

          D 1 Reply Last reply
          0
          • B [email protected]

            Ah, the ol' tristate boolean switcheroo

            K This user is from outside of this forum
            K This user is from outside of this forum
            [email protected]
            wrote last edited by [email protected]
            #50

            tristate as in three states or tristate as in five states?

            P B 2 Replies Last reply
            2
            • K [email protected]

              tristate as in three states or tristate as in five states?

              P This user is from outside of this forum
              P This user is from outside of this forum
              [email protected]
              wrote last edited by
              #51

              Is that a quantum boolean?

              1 Reply Last reply
              2
              • T [email protected]
                This post did not contain any content.
                B This user is from outside of this forum
                B This user is from outside of this forum
                [email protected]
                wrote last edited by
                #52

                And what if it's undefined?

                T 1 Reply Last reply
                3
                • maiq@lemy.lolM [email protected]

                  That's good to know. Don't know how I didn't know this. Been writing JS since 2000. Always just used them I guess. Ecmascripts look funny to me without them

                  S This user is from outside of this forum
                  S This user is from outside of this forum
                  [email protected]
                  wrote last edited by [email protected]
                  #53

                  Fair enough, I like it better without but I don't have a strong preference and have no issue adapting to whatever the style of the repo is.

                  I learned about it researching tools to automatically enforce formatting style and came across StandardJS, which eliminates them by default.

                  maiq@lemy.lolM 1 Reply Last reply
                  1
                  • E [email protected]

                    Hmm, a webdev colleague said he'd normally prefer without semicolons, but used them anyways for better compile errors.

                    S This user is from outside of this forum
                    S This user is from outside of this forum
                    [email protected]
                    wrote last edited by
                    #54

                    Interesting, I'm not aware of any way they would affect compile errors. I'd be curious to know more.

                    E 1 Reply Last reply
                    0
                    • K [email protected]

                      tristate as in three states or tristate as in five states?

                      B This user is from outside of this forum
                      B This user is from outside of this forum
                      [email protected]
                      wrote last edited by [email protected]
                      #55

                      That is the jankiest thing I have seen in at least ten years.

                      Edit: because of course it's office.

                      1 Reply Last reply
                      1
                      • S [email protected]

                        Fair enough, I like it better without but I don't have a strong preference and have no issue adapting to whatever the style of the repo is.

                        I learned about it researching tools to automatically enforce formatting style and came across StandardJS, which eliminates them by default.

                        maiq@lemy.lolM This user is from outside of this forum
                        maiq@lemy.lolM This user is from outside of this forum
                        [email protected]
                        wrote last edited by
                        #56

                        I can see the benefit of matching style when working with others. I only code for myself and never had to worry about conformity for project consistency.

                        It is good to learn new things.

                        I'm sure I have some coding habitats that would annoy others.

                        S 1 Reply Last reply
                        0
                        • bjoern_tantau@swg-empire.deB [email protected]

                          FILE_NOT_FOUND is from an old story on thedailywtf.com. Someone created a boolean enum with TRUE, FALSE and FILE_NOT_FOUND, if I recall correctly. It's been a recurring running joke.

                          foxglove@lazysoci.alF This user is from outside of this forum
                          foxglove@lazysoci.alF This user is from outside of this forum
                          [email protected]
                          wrote last edited by
                          #57

                          thank you for letting me in on the joke 😄

                          and for catching my error!

                          J 1 Reply Last reply
                          1
                          • maiq@lemy.lolM [email protected]

                            I can see the benefit of matching style when working with others. I only code for myself and never had to worry about conformity for project consistency.

                            It is good to learn new things.

                            I'm sure I have some coding habitats that would annoy others.

                            S This user is from outside of this forum
                            S This user is from outside of this forum
                            [email protected]
                            wrote last edited by
                            #58

                            Consistent styling helps make the actual meaningful changes easier to spot. Probably also useful for your own commit history when working solo in a repo, but most useful in a team, yeah!

                            1 Reply Last reply
                            1
                            • S [email protected]

                              Interesting, I'm not aware of any way they would affect compile errors. I'd be curious to know more.

                              E This user is from outside of this forum
                              E This user is from outside of this forum
                              [email protected]
                              wrote last edited by
                              #59

                              I don't have experience with how it affects JavaScript specifically, but independent of programming language, it usually removes the guesswork where the error might be.

                              The thing is that compilers use fairly static rules for their grammar. So, even if you just typo a comma where there should've been a dot, then its grammar rules don't match anymore and it doesn't really know what to do with your code.
                              To some degree, it's possible to say certain symbols just cannot appear in a specific place, but especially with a comma, it could be the start of the next element in a list, for example.

                              Without semicolons, it's likely going to tell you that something's wrong between somewhere before your typo and the next closing brace (}). With semicolons, it can generally pinpoint the specific statement where the comma is wrong.
                              This should also make analysis quicker while you're editing the code, as it only has to check one statement (or two, if you're inserting a new line and haven't typed the semicolon yet).

                              1 Reply Last reply
                              0
                              • B [email protected]

                                And what if it's undefined?

                                T This user is from outside of this forum
                                T This user is from outside of this forum
                                [email protected]
                                wrote last edited by
                                #60

                                root access

                                1 Reply Last reply
                                8
                                • foxglove@lazysoci.alF [email protected]

                                  thank you for letting me in on the joke 😄

                                  and for catching my error!

                                  J This user is from outside of this forum
                                  J This user is from outside of this forum
                                  [email protected]
                                  wrote last edited by
                                  #61

                                  Welcome! I guess this is your Ten Thousand moment for a mediocre joke for old programmers. 💪👍

                                  foxglove@lazysoci.alF 1 Reply Last reply
                                  1
                                  • B [email protected]

                                    Ah, the ol' tristate boolean switcheroo

                                    N This user is from outside of this forum
                                    N This user is from outside of this forum
                                    [email protected]
                                    wrote last edited by
                                    #62

                                    Classic checkbox values

                                    B 1 Reply Last reply
                                    1
                                    • N [email protected]

                                      Classic checkbox values

                                      B This user is from outside of this forum
                                      B This user is from outside of this forum
                                      [email protected]
                                      wrote last edited by
                                      #63

                                      Yup. Checked, unchecked, and not checked.

                                      1 Reply Last reply
                                      0
                                      • J [email protected]

                                        Welcome! I guess this is your Ten Thousand moment for a mediocre joke for old programmers. 💪👍

                                        foxglove@lazysoci.alF This user is from outside of this forum
                                        foxglove@lazysoci.alF This user is from outside of this forum
                                        [email protected]
                                        wrote last edited by
                                        #64

                                        haha, yes - exactly! At least I got that reference, xkcd is pretty well known, though.

                                        J 1 Reply Last reply
                                        1
                                        • foxglove@lazysoci.alF [email protected]

                                          haha, yes - exactly! At least I got that reference, xkcd is pretty well known, though.

                                          J This user is from outside of this forum
                                          J This user is from outside of this forum
                                          [email protected]
                                          wrote last edited by
                                          #65

                                          I see that they've gone back to the name "The Daily WTF". For some time, they changed to "Worse than failure" in order to avoid not even the word "fuck". 🤷

                                          https://thedailywtf.com/

                                          1 Reply Last reply
                                          1
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups