• cookie_sabotage@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 months ago
    public class GameManager : MonoBehaviour
    {
        public bool EnableHighContrast;
        public bool PlayerWon;
        public float PlayerUnitsMoved;
        public int PlayerDeathCount;
        public float PlayerHealth;
    
        public void PlayerTakeDamage(float damage)
        {
            PlayerHealth -= damage;
            if (PlayerHealth < 0)
            {
                PlayerDieAndRespawn();
            }
        }
    
        public void PlayerDieAndRespawn()
        {
            return;
        }
    }
    

    I couldn’t contain myself.

    • Wise@feddit.uk
      link
      fedilink
      English
      arrow-up
      0
      ·
      3 months ago

      Should it be

      PlayerHealth <= 0
      

      ?

      Otherwise the player could have 0 health and not die? I’m sleep deprived so forgive me if I’m wrong

      • vithigar@lemmy.ca
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        3 months ago

        You are correct about it allowing you to have zero health and not die, but whether or not that’s the correct behavior will depend on the game. Off the top of my head I know that Street Fighter, some versions at least, let you cling to life at zero.

      • Randomocity@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        0
        ·
        3 months ago

        This won’t work if you can ever take more than 1 damage. If you were at 1 and received 2 damage you would become invincible. You’d want to do less than or equal to.

      • joshfaulkner@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        3 months ago

        I know this is /c/Progammerhumor, but I wanted to pull on this thread a little bit for my own edification. I’m a Python guy and have been a while, but I’ve dabbled in other languages. The screenshot says “MonoBehaviour” which makes me assume this is mono or a .Net-like language (you know what happens when you assume).

        If your player health is a float, would mono or .Net have an issue comparing the float with integer zero “0”? I mean, it seems like floating point precision may make it impossible for it to ever “equal” integer zero, but it also seems like the code isn’t accounting for that precision error.

        Am I overthinking this?

        • herrvogel@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          3 months ago

          Floating point errors are a product of how floating points work as a mathematical concept. So they’re independent of the programming language and can happen everywhere.

          In this case though, I doubt it’s a critical issue. So the player “died” when they actually had 0.000000000027 hp left or whatever. Who cares? Do you need to be that precise?

    • Ironfacebuster@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      Too readable, please make each name a paragraph describing its function and how it relates to the other variables/functions around it

      • TheOakTree@lemm.ee
        link
        fedilink
        arrow-up
        0
        ·
        3 months ago

        Well if you have a “down but not dead” condition then yes, you could escape a fight with 0 health (assuming you have teammates/pawns that can save you).

  • MachineFab812@discuss.tchncs.de
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    When the variable name is the description that should be in the comments.

    Idea: Comments that automattically populate the end of any line a given variable is invoked on, including spelling out formulas from that line. ie: float y=mx+b // (cartesian y value)=(slope)(cartesian x value)+(cartisian y-intercept)

    “Duplicated” coments not actually in the file, but specified witt the creation of such variables and spread around by the code editor /IDE.

    • paholg@lemm.ee
      link
      fedilink
      English
      arrow-up
      0
      ·
      3 months ago

      Then, you could take those comments, and have the compiler use them to ensure you’re using the right variable in the right place. Oh wait, we just invented a type system.

  • danhab99@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    You forgot to declare custom primitive types. You cannot create a bool you gotta declare a DoubleYouDoubleYouDoubleYouDotLemmyGradDotML_Bool

  • Anna@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    Aah… Like reading a novel. But with a lot of weird punctuation… Or maybe just like a novel then.

  • tobogganablaze@lemmus.org
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    3 months ago

    I mean, this is overdoing it a bit and the “thisVarMakesItSoThat” part is redundant, but other than that those are very descriptive property- and method names, which is not a bad thing.

    • rbits@lemm.ee
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      It wouldn’t need to say HighContrastForAccessibilityPurposes though, it would ideally just be HighContrast, and the “for accessibility purposes” would be a comment, right?

      • deadcream@sopuli.xyz
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        3 months ago

        Variable names shouldn’t need comments, period. You don’t want to look it up every time this variable is used in code, just to understand what it holds. Of course there are always exceptions, but generally names should be descriptive enough to not need additional explanation.

        And context can also come from names of other things, e.g. name of a class / namespace that holds this variable. For example AccessibilitySettings.HighContrast, where AccessibilitySettings holds all options related to accessibility.

        • 4am@lemm.ee
          link
          fedilink
          arrow-up
          0
          ·
          3 months ago

          Yeah but “HighContrast” is enough; if you need to know the Why and not the What you can find a comment at the definition. There’s not need to carry the whole Wiki article everytime you need to use the variable.

          • Kushan@lemmy.world
            link
            fedilink
            English
            arrow-up
            0
            ·
            3 months ago

            I think the argument about “for accessibility” is missing the point a little bit and a common mistake most developers make.

            You should endeavour to make your interface accessible by default. You shouldn’t be thinking in terms of “okay here’s the design and here’s the design that’s accessible”, you should be considering accessibility in all of your designs.

            Now that’s usually a bit harder with games because you have styles and themes that you don’t want to detract from, but if your interface causes accessibility issues, it’s generally going to be bad for people that don’t have accessibility needs as well.

            Accessibility benefits everyone.

      • tobogganablaze@lemmus.org
        link
        fedilink
        English
        arrow-up
        0
        ·
        edit-2
        3 months ago

        Well the “Purposes” can definitly be dropped. I guess “HighContrast” would be enough if there is only a single high contrast setting, but if there are multiple then I think “HighContrastForAccessibility” would be totally fine.

  • Cosmic Cleric@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    3 months ago

    I don’t (brain processes the photons bouncing off the object and colliding with the cones and rods in the retina) a problem with this.

    (See what I did there?)

    (I think I met my dad joke quota for the month.)

  • CanadaPlus@lemmy.sdf.org
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    3 months ago

    Hot take, but the main problem with this is that you have to type variables or use them in larger expressions. Otherwise I like it.

    These would make a great mouseover text. I don’t know if there’s any standard way to support that. Actually, how come coding in non-plaintext formats never took off?

  • JakenVeina@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    3 months ago

    I’ll take this over the more “classic” styles, when people seed to believe they were paying the compiler by the character.

  • vacuumoftalent@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    Looks ugly until you need to implement something and realize you’ve been blessed with a description of business logic.

    • BeigeAgenda@lemmy.ca
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      Until they find out that the way to descriptive variables or functions needs to be extended with new business logic requiring renaming of functions again and again.

      I think maintaining code with this level of verbose naming, will be a pain over time. If they don’t let the naming slip, and then they could as well use cryptic 3 letter names.