this post was submitted on 28 Mar 2024
611 points (98.1% liked)

Programmer Humor

32410 readers
1 users here now

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

Rules:

founded 6 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] cookie_sabotage@sh.itjust.works 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.

[–] wise@feddit.uk 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

[–] bassomitron@lemmy.world 27 points 2 years ago (1 children)
[–] wise@feddit.uk 54 points 2 years ago (1 children)

Counting this meme as my first FOSS contribution

[–] SidewaysHighways@lemmy.world 12 points 2 years ago

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

[–] mryessir@lemmy.sdf.org 26 points 2 years ago

Open up ticket first, please. Thanks Codemonkey.

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

load more comments (5 replies)
[–] blarth@thelemmy.club 34 points 2 years ago (2 children)

Yay, escaped the fight with 0 health!

[–] TheOakTree@lemm.ee 15 points 2 years 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 2 years ago (1 children)

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

[–] cookie_sabotage@sh.itjust.works 15 points 2 years ago (1 children)

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 2 years ago (1 children)

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 2 years ago

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

[–] NeatNit@discuss.tchncs.de 102 points 2 years ago (1 children)

gestures at ~~butterfly~~ this code

Is this self-documenting code?

[–] skulblaka@startrek.website 40 points 2 years ago (1 children)

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 2 years ago (5 children)

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 2 years ago (2 children)

I would take this over int a; anyday

[–] intelisense@lemm.ee 31 points 2 years ago (1 children)

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

[–] RogueBanana@lemmy.zip 27 points 2 years ago (5 children)

Cmon now its illegal to use them anywhere other than iterators

load more comments (5 replies)
[–] Ironfacebuster@lemmy.world 18 points 2 years ago

int IntegerThatWillBeUsedToIterateOverAListOfItemsAndModifyThem2

[–] hstde@feddit.de 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.

[–] jballs@sh.itjust.works 7 points 2 years ago (1 children)

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 2 years ago

IDE renames all references, no issue

load more comments (1 replies)
[–] tobogganablaze@lemmus.org 48 points 2 years ago* (last edited 2 years ago) (1 children)

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 2 years ago (3 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?

[–] deadcream@sopuli.xyz 11 points 2 years ago* (last edited 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.

load more comments (2 replies)
load more comments (2 replies)
[–] Hupf@feddit.de 31 points 2 years ago (1 children)
[–] Fraqual@feddit.de 31 points 2 years ago

Deobfuscated code

[–] reverendsteveii@lemm.ee 22 points 2 years ago

yeah, PascalCase is the worst

[–] JakenVeina@lemm.ee 21 points 2 years ago (1 children)

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 2 years ago (1 children)

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)
[–] Socsa@sh.itjust.works 16 points 2 years ago

Self documenting!

[–] thegiddystitcher@lemm.ee 16 points 2 years ago

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

[–] vacuumoftalent@lemmy.world 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.

[–] flumph@programming.dev 17 points 2 years ago

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

load more comments (1 replies)
[–] warlaan@lemm.ee 14 points 2 years ago* (last edited 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.

load more comments (6 replies)
[–] Andromxda@lemmy.dbzer0.com 12 points 2 years ago
[–] muhyb@programming.dev 10 points 2 years ago

"Commenting is for n00bs"

[–] danhab99@programming.dev 9 points 2 years ago

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

[–] s12@sopuli.xyz 8 points 2 years ago

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

[–] summerof69@lemm.ee 8 points 1 year ago

Self-explanatory code doesn't need comments!

[–] Razzazzika@lemm.ee 7 points 2 years ago

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

[–] LeLachs@lemmy.ml 6 points 2 years ago (2 children)

String if_you_must_please_at_least_separate_the_words

[–] ulterno@lemmy.kde.social 7 points 2 years ago

That's just camel case vs snake case (though in this case, it also has the first character capitalised)

load more comments (1 replies)
[–] CanadaPlus@lemmy.sdf.org 6 points 2 years ago* (last edited 2 years ago) (3 children)

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?

load more comments (3 replies)
load more comments
view more: next ›