this post was submitted on 08 Oct 2023
1015 points (96.6% liked)

Programmer Humor

19187 readers
1129 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] idunnololz@lemmy.world 77 points 11 months ago (6 children)

Just create a global object and stuff your variable in there. Now you have a global singleton and that's not a purely bad practice :D

[–] Techmaster@lemm.ee 40 points 11 months ago

Just call it "state management" and nobody will even care.

[–] magic_lobster_party@kbin.social 38 points 11 months ago (1 children)

Not necessarily a bad practice if the singleton is immutable, and it’s provided via dependency injection for example.

[–] wreckedcarzz@lemmy.world 34 points 11 months ago (1 children)

As a hobby coder: "mmmhm, mmmm, mmhm... I know some of these words!"

[–] SkyNTP@lemmy.ml 32 points 11 months ago* (last edited 11 months ago)

Software dev is full of obscure keywords that describe otherwise pretty simple or basic concepts you stumble upon in practice naturally and that you probably already understand.

  • singleton: a class/object that is designed to be single use, i.e. only ever instantiated with a single instance. Typically used when you use class/objects more for flow control or to represent the state of the program itself, rather than using it to represent data
  • immutable: read-only, i.e. unchangeable
  • dependency injection: basically when you pass a function or object into another function object, thereby extending their effective functionality, typically for modular code and to separate concerns.

Here's one more of my favourite examples of such a keyword: memoization

[–] Anonymousllama@lemmy.world 20 points 11 months ago (1 children)

Important to contain all your mess to one side of the room, makes it easier to manage

[–] shotgun_crab@lemmy.world 2 points 11 months ago

Yeah yeah let's put all the eggs in one basket

[–] xmunk@sh.itjust.works 7 points 11 months ago* (last edited 11 months ago) (2 children)

Real enterprise programmers know that everything should be on the stack... so they declare a List《void*》 in main.

[–] idunnololz@lemmy.world 7 points 11 months ago

But we might need to add more features in the future so it might not just be a list in a few years. Better encapsulate it in a few layers of abstractions just to be safe.

[–] manapropos@lemmy.basedcount.com 3 points 11 months ago

Real enterprise programmers know you can get another job in the next year or two so fuck best practice

[–] HurgletOfficial@lemmy.basedcount.com 1 points 11 months ago (1 children)

I do this all the time in Python by creating a class like

class Core:
    foo = "bar"
[–] ryannathans@aussie.zone 3 points 11 months ago (1 children)

That's not immutable nor a singleton

[–] xmunk@sh.itjust.works 3 points 11 months ago

That makes it inherently multithread compatible!

[–] z3rOR0ne@lemmy.ml 1 points 11 months ago

Ah yes. Global Objects, AKA the thinnest of condoms, lol.