this post was submitted on 12 Sep 2024
288 points (96.5% liked)

Programmer Humor

19187 readers
1536 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 

var Turtle1 var Turtle2 var Is_Turtle

top 50 comments
sorted by: hot top controversial new old
[–] Kojichan@lemmy.world 2 points 5 days ago

I remember an old mentor programmer I had who basically described his job as building an addition to an addition to an addition on a tree house built in a twig.

[–] SteevyT@beehaw.org 3 points 6 days ago

Wait, what do you mean x3, y2, and x37 are not good variable names?

[–] henfredemars@infosec.pub 47 points 1 week ago (1 children)

Try assembly language! You have registers, and they are named for you with highly memorable names like R17.

[–] ma1w4re@lemm.ee 15 points 1 week ago (1 children)

ngl RAX actually sounds cool and is memorable 🥺

[–] henfredemars@infosec.pub 5 points 6 days ago

RIP.

Don’t recommend using that register to store your variables.

[–] parpol@programming.dev 23 points 1 week ago* (last edited 1 week ago) (3 children)

Yeah, a name should describe what it is or does, so if you have two turtles, and let's say turtle1 wants to shit on turtle2's lawn, you could name them shittingTurtle and victimTurtle. If the name alone tells you what its purpose is, that saves a lot of time for people looking at your code.

Is_Turtle is not a bad variable name because it tells you it is a Boolean with "is" and that the Boolean tells you whether something is a turtle or not.

Also, depending on the language, I suggest either camelCase or snake_case naming of variables. PascalCase is usually for defining classes or in case of C#, methods.

[–] MajorHavoc@programming.dev 3 points 6 days ago

Thank you for this. This is awesome.

shittingTurtle and victimTurtle are going into one of my professional slide decks as soon as I think I can get away with it.

[–] Repelle@lemmy.world 12 points 1 week ago (1 children)

SHOUTING_SNAKE_CASE aka SCREAMING_SNAKE_CASE is the best case for all use cases, because it gives you a chance to use its wonderful names.

[–] Klear@lemmy.world 13 points 1 week ago (1 children)
[–] MajorHavoc@programming.dev 8 points 1 week ago* (last edited 1 week ago)

Thanks. I hate it.

I consider myself a collector of programming anti-patterns, but I didn't have this one yet.

[–] OttoVonNoob@lemmy.ca 4 points 1 week ago* (last edited 1 week ago)

I'm gonna be honest I just used Turtle ad an example:X .. when it's actually like a GoldCost, GoldC and GoldH. Where GoldR is a reset var and GoldC is the paid value. GoldCost is self explanatory but I really spagettied it up XD...

[–] r00ty@kbin.life 10 points 1 week ago (1 children)

An array?

var turtles = new Turtle[] { new Turtle(), new Turtle() };

Don't do this :P

[–] Hupf@feddit.org 6 points 1 week ago

But I like tautological variable names

also turtles

[–] wesker@lemmy.sdf.org 9 points 1 week ago* (last edited 1 week ago) (2 children)

Have you considered using inheritance?

[–] metaStatic@kbin.earth 19 points 1 week ago (1 children)

blew my inheritance on hookers and blow, now what?

[–] _stranger_@lemmy.world 11 points 1 week ago* (last edited 1 week ago) (2 children)

Have you considered multiple inheritance. It's an upgrade. All upside, literally no downside. I'm trustworthy. Trust me.

Idunno, my mom told me not to talk to _stranger_s 🤔

... She said a lot of things that were BS, though, so maybe you're cool I guess? 🤷

[–] InternetCitizen2@lemmy.world 4 points 1 week ago (1 children)

You might not like it, but that is what peak shareholders value looks like.

[–] MajorHavoc@programming.dev 2 points 1 week ago (1 children)

Wow. "peak shareholder value" is what I shall now call "multiple inheritance", from now on.

[–] InternetCitizen2@lemmy.world 2 points 1 week ago

I like it. I'd let you serve as a CTO at my beloved corp

[–] OttoVonNoob@lemmy.ca 4 points 1 week ago (2 children)

I'm an amateur I'm not sure what inheritance is:X? Is it like instantiateing?

[–] wesker@lemmy.sdf.org 6 points 1 week ago* (last edited 1 week ago) (2 children)

When you start learning about different paradigms, you'll likely learn much more about inheritance when learning about the Object Oriented design paradigm.

To overly simplify, you create objects that inherit attributes from other objects. It's for instance a way to create reusable patterns, that have stronger and more reliable data structures.

I made the joke comment, because for instance, you could create a Turtle class, and always know it was a Turtle. Again, an oversimplification.

EDIT: I should also add that for some reason OOP is an oddly divisive subject. Developers always seem to want to argue about it.

[–] hoshikarakitaridia@lemmy.world 6 points 1 week ago (3 children)

At this point I think there is no software dev topic that is somehow not devisive.

load more comments (3 replies)
[–] OttoVonNoob@lemmy.ca 3 points 1 week ago (3 children)

Oh yea, class resources. That would work! Thanks.im going to have to into this more, as it's going to be useful

[–] arendjr@programming.dev 3 points 1 week ago (2 children)

Just keep in mind that inheritance is nowadays a very contested feature. Even most people still invested in object oriented programming recognise that in hindsight inheritance was mostly a mistake. The industry as a whole is also making a shift to move more towards functional programming, in which object orientation as a whole is taking more of a backseat and inheritance specifically is not even supported anymore. So yeah, take the chance to learn, but be cautious before going into any one direction too deeply.

load more comments (2 replies)
load more comments (2 replies)
[–] ma1w4re@lemm.ee 3 points 1 week ago* (last edited 1 week ago) (1 children)

Inheritance established "is a" relationship between classes.

class Turtle;  
class TigerTurtle is a Turtle (but better);  
class BossTurtle is a Turtle (but better);  

Underlying classes hold an inner object to the super class, everything from Turtle will be in TigerTurtle and BossTurtle.

In some languages that is configurable with public, private, protected keywords.

Relatedly, there's also composition, which establishes a "has a" relationship:

class TurtleTail; class Turtle: var tail: TurtleTail; (has a tail)

Since Turtle is NOT a tail, but a whole animal, turtle should not inherit TurtleTail. But it HAS a tail, thus we add turtle tail as a property.

[–] _stranger_@lemmy.world 3 points 1 week ago* (last edited 1 week ago) (1 children)

I'm only commenting because the actual python is practically pseudo code:


# A turtle class
class Turtle:
    shell=True

# A boss class
class Boss:
    authority=True

#A class that inherits from another
class TigerTurtle(Turtle):
    fuzzy=True

# Multiple inheritance, or "The Devil's Playground"
class TigerBossTurtle(TigerTurtle, Boss):
    #  shell, authority, and fuzzy are all true
    ...
[–] ma1w4re@lemm.ee 2 points 1 week ago

It is simpler than my faulty memory remembers, time to learn python again 😁

[–] Skullgrid@lemmy.world 5 points 1 week ago (1 children)
[–] Leate_Wonceslace@lemmy.dbzer0.com 5 points 1 week ago (1 children)

What's wrong with making a recursive function in a recursive function with variables M, m, N, n? It's perfectly fine when I'm writing infinite series.

[–] CanadaPlus@lemmy.sdf.org 1 points 6 days ago (1 children)

If we're talking mathematicians, you just know it's going to be ω-nested recursive functions any moment now. Just be grateful it's not all n with polynomial subscripts or something.

[–] Leate_Wonceslace@lemmy.dbzer0.com 1 points 6 days ago (1 children)

Polynomial subscripts sound awesome, ngl. Never seen it before; I want to know what the applications are.

[–] CanadaPlus@lemmy.sdf.org 1 points 6 days ago* (last edited 6 days ago)

Uhh, I'm pretty sure I've seen that, but I'm not sure where now. Any time you need to access a member of a list or array that's determined by a polynomial - which by Horner's rule covers all combinations of multiplications and additions - it would be a possible notation.

Transfinite algorithms are definitely a topic of research.

[–] Kolanaki@yiffit.net 4 points 1 week ago* (last edited 1 week ago)

I always make sure my variables are named in ways I can remember what they're for. The only time I just use generic var1, var2, etc is if I am experimenting with a function I've never used before and wanna play around with it to see how it's used.

This should be easily read by others but there could be times where it's an inside joke.

[–] NigelFrobisher@aussie.zone 4 points 1 week ago

Based LOGO programmer.

[–] some_guy@lemmy.sdf.org 3 points 1 week ago

Because I mostly (almost exclusively) write shell scripts, my vars are often like this: theList, workingDir, etc.

I'm a monster. But it works for me.

[–] umbraroze@lemmy.world 3 points 1 week ago

This is a very cute thread. I love turtles and I like them for their vast computer science skills too.

[–] MajorHavoc@programming.dev 3 points 1 week ago

All great code started out as a shitty work-around that happened to work.

(I say this as someone with one of the more prestigious pedigrees in "not writing shit code". All the theory I've learned helps, but at the end of the day the most important qualities of a line of code are: whether it got the job done, and whether is was obviously correct enough that the next developer left it alone.)

[–] CodexArcanum@lemmy.world 2 points 1 week ago

All these jokes about naming variables and yet no serious suggestions that if you have a turtle2, what you really need is a turtle array. I like to block out all the memory I'll need for the whole program up front, put it all in one big array, and then I can use clean, easy to remember numbers for all my variables!

[–] sheepishly@fedia.io 2 points 1 week ago (1 children)
[–] OttoVonNoob@lemmy.ca 1 points 6 days ago (1 children)

Who? I made this you can tell by the imgflip in corner and PNG spaghetti xD...

[–] sheepishly@fedia.io 2 points 6 days ago (1 children)

T'was a joke. He's a programmer guy on Youtube who uses a turtle avatar.

[–] OttoVonNoob@lemmy.ca 1 points 6 days ago

Ahh ok:p my bad xD.. I was like I made this shitty meme no way someone stole it!

[–] Sanctus@lemmy.world 2 points 1 week ago (2 children)

Yes, its code whether it executes or not.

load more comments (2 replies)
[–] OpenStars@discuss.online 2 points 1 week ago

Yes your variable names should indeed all be different from one another.

var Turtle1 var Turtle1 var Turtle1

just doesn't quite have the same impact:-).

load more comments
view more: next ›