top 50 comments

sorted by: hot top controversial new old
[–] 159 points 2 years ago (4 children)
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.

  • source
  • hideshow 7 child comments
  • [–] 57 points 2 years ago (8 children)

    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

  • source
  • parent
  • hideshow 11 child comments
  • [–] 12 points 2 years 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.

  • source
  • parent
  • load more comments (5 replies)
  • load more comments (1 reply)
    [–] 112 points 2 years ago (1 child)

    Great. Now that my code is self-documenting it is somehow also not legible?

    Make up your damn minds, peeps!

  • source
  • hideshow 2 child comments
  • [–] 101 points 2 years ago (1 child)

    gestures at butterfly this code

    Is this self-documenting code?

  • source
  • hideshow 2 child comments
  • [–] 39 points 2 years ago (1 child)

    I genuinely believe something like this is what some of my professors wanted me to submit back in school. I once got a couple points off a project for not having a clarifying comment on every single line of code. I got points off once for not comment-clarifying a fucking iterator variable. I wish I could see what they would have said if I turned in something like this. I have a weird feeling that this file would have received full marks.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 71 points 2 years ago (2 children)

    I would take this over int a; anyday

  • source
  • hideshow 4 child comments
  • [–] 71 points 2 years ago (2 children)

    This is something that can easily get refactored, because the purpose of alia the variables is right there in the name. This is way better that spending three days to try to figure out what the purpose of var1 is.

  • source
  • hideshow 3 child comments
  • [–] 7 points 2 years ago (1 child)

    Nah, refactoring this would be a bitch. Your function name contains everything that happens in the function. Which means if you add something to it, you also have to change the name of the function. So CallThisWhenThePlayerTakesDamageAndIfThePlayerHealthIsLessThanZeroThenAlsoTheyDie would have to go to something like CallThisWhenThePlayerTakesDamageAndIfThePlayerHealthIsLessThanZeroThenAlsoTheyDieAndIncrementTheTotalDamageTakenCounter if you added something else.

  • source
  • parent
  • hideshow 2 child comments
  • load more comments (1 reply)
    [–] 48 points 2 years ago* (1 child)

    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.

  • source
  • hideshow 2 child comments
  • [–] 11 points 2 years ago (2 children)

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

  • source
  • parent
  • hideshow 4 child comments
  • [–] 11 points 2 years ago* (2 children)

    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.

  • source
  • parent
  • hideshow 2 child comments
  • load more comments (2 replies)
  • [–] 31 points 2 years ago (1 child)
  • [–] 30 points 2 years ago

    Deobfuscated code

  • source
  • [–] 22 points 2 years ago

    yeah, PascalCase is the worst

  • source
  • [–] 21 points 2 years ago (1 child)

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

  • source
  • hideshow 2 child comments
  • [–] 16 points 2 years ago

    Self documenting!

  • source
  • [–] 16 points 2 years ago

    Starting my day off with this absolutely cursed image, thank you OP.

  • source
  • [–] 14 points 2 years ago (2 children)

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

  • source
  • hideshow 3 child comments
  • load more comments (1 reply)
    [–] 14 points 2 years ago* (6 children)

    The real naming fail is calling the class "GameManager", still my number one pet peeve. With a class name as vague as that you would have to add tons of information into the variable name. (Also the class name begs for unorganized code. I mean name one function or variable that you could not justify putting into the "GameManager" class. After all if it's managing the game it could justifiably perform any process in the game and access any state in it.)

    Once you put the first bool into a class with a name like AccessibilitySettings, calling it something like HighContrast is completely sufficient.

  • source
  • hideshow 6 child comments
  • load more comments (6 replies)
    [–] 12 points 2 years ago
    [+] 11 points 2 years ago* (last edited 1 year ago) (1 child)
  • [–] 10 points 2 years ago

    "Commenting is for n00bs"

  • source
  • [–] 9 points 2 years ago

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

  • source
  • [–] 8 points 2 years ago

    I see. So that’s why people put comments before variable declarations.

  • source
  • [–] 8 points 2 years ago

    Self-explanatory code doesn't need comments!

  • source
  • [–] 7 points 2 years ago

    Like... there's such a thing as comments my dude.

  • source
  • [–] 6 points 2 years ago (2 children)

    String if_you_must_please_at_least_separate_the_words

  • source
  • hideshow 3 child comments
  • load more comments (1 reply)
    load more comments
    view more: next ›