614
top 50 comments
sorted by: hot top controversial new old
[-] cookie_sabotage@sh.itjust.works 159 points 8 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 57 points 8 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

[-] bassomitron@lemmy.world 27 points 8 months ago
[-] wise@feddit.uk 54 points 8 months ago

Counting this meme as my first FOSS contribution

[-] SidewaysHighways@lemmy.world 12 points 8 months ago

Holy shit I was there with you sir! With the zeros and stuff

[-] mryessir@lemmy.sdf.org 26 points 8 months ago

Open up ticket first, please. Thanks Codemonkey.

[-] vithigar@lemmy.ca 12 points 8 months ago* (last edited 8 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.

load more comments (5 replies)
[-] blarth@thelemmy.club 34 points 8 months ago

Yay, escaped the fight with 0 health!

[-] TheOakTree@lemm.ee 15 points 8 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).

load more comments (1 replies)
[-] Sakychu@lemmy.world 10 points 8 months ago

I called the takeDamage function and my player disappeared: send 'elp everything foobar

[-] cookie_sabotage@sh.itjust.works 15 points 8 months ago

Don't worry! this issue will be fixed in the next patch. In the meantime just try not getting hit.

load more comments (1 replies)
load more comments (1 replies)
[-] BatrickPateman@feddit.de 112 points 8 months ago

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

Make up your damn minds, peeps!

[-] childOfMagenta@lemm.ee 22 points 8 months ago

Is this... clean code ? 💁‍♂️ 🦋

[-] NeatNit@discuss.tchncs.de 101 points 8 months ago

gestures at ~~butterfly~~ this code

Is this self-documenting code?

[-] skulblaka@startrek.website 39 points 8 months ago

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.

[-] maniclucky@lemmy.world 12 points 8 months ago

Did you have my professor for intro to C? This guy was well known for failing people for plagiarism on projects where the task was basically "hello world". And he disallowed using if/else for the first month of class.

load more comments (5 replies)
[-] RogueBanana@lemmy.zip 71 points 8 months ago

I would take this over int a; anyday

[-] intelisense@lemm.ee 31 points 8 months ago

Amateur! Ints should be called i, j or k.

[-] RogueBanana@lemmy.zip 27 points 8 months ago

Cmon now its illegal to use them anywhere other than iterators

load more comments (5 replies)
[-] Ironfacebuster@lemmy.world 18 points 8 months ago

int IntegerThatWillBeUsedToIterateOverAListOfItemsAndModifyThem2

[-] hstde@feddit.de 70 points 8 months ago

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.

[-] jballs@sh.itjust.works 7 points 8 months ago

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.

[-] Hotzilla@sopuli.xyz 11 points 8 months ago

IDE renames all references, no issue

[-] princess@lemmy.blahaj.zone 6 points 8 months ago

oh such hope

in a week IntegerThatTracksOneThingForOnePurpose will be an object tracking 30% of the game state and mutated in 15 places without ever being renamed

load more comments (1 replies)
[-] tobogganablaze@lemmus.org 49 points 8 months ago* (last edited 8 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 11 points 8 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 11 points 8 months ago* (last edited 8 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.

load more comments (2 replies)
[-] tobogganablaze@lemmus.org 6 points 8 months ago* (last edited 8 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.

load more comments (1 replies)
[-] Hupf@feddit.de 31 points 8 months ago
[-] LostXOR@fedia.io 12 points 8 months ago

Always a relevant xkcd.

[-] Fraqual@feddit.de 30 points 8 months ago

Deobfuscated code

[-] reverendsteveii@lemm.ee 22 points 8 months ago

yeah, PascalCase is the worst

[-] JakenVeina@lemm.ee 21 points 8 months ago

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

[-] Theharpyeagle@lemmy.world 7 points 8 months ago

I respect code golfers the same way I respect a cobra, from a distance. Don't bring that single character naming to the codebase please.

load more comments (1 replies)
[-] thegiddystitcher@lemm.ee 16 points 8 months ago

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

[-] Socsa@sh.itjust.works 16 points 8 months ago

Self documenting!

[-] warlaan@lemm.ee 14 points 8 months ago* (last edited 8 months ago)

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.

load more comments (6 replies)
[-] vacuumoftalent@lemmy.world 14 points 8 months ago

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

[-] flumph@programming.dev 17 points 8 months ago

Strong names are great, but (sometimes) mentioning the type of variable in the name is redundant.

load more comments (1 replies)
[-] Andromxda@lemmy.dbzer0.com 12 points 8 months ago
[-] prosp3kt@lemmy.dbzer0.com 11 points 8 months ago

Bruh didn't know how to use comments to describe a function or variable...

[-] waz@lemmy.world 16 points 8 months ago

Clearly this is what we call "self documenting code".

[-] muhyb@programming.dev 10 points 8 months ago

"Commenting is for n00bs"

[-] summerof69@lemm.ee 9 points 8 months ago

Self-explanatory code doesn't need comments!

[-] danhab99@programming.dev 9 points 8 months ago

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

[-] s12@sopuli.xyz 8 points 8 months ago

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

[-] Razzazzika@lemm.ee 7 points 8 months ago

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

load more comments
view more: next ›
this post was submitted on 28 Mar 2024
614 points (98.1% liked)

Programmer Humor

32591 readers
1073 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS