this post was submitted on 07 Oct 2025
170 points (91.3% liked)

Programmer Humor

26846 readers
2598 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 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] ArsonButCute@lemmy.dbzer0.com -5 points 5 days ago* (last edited 5 days ago) (2 children)

Is... Its that a fork bomb..? Stored inside a class?

Edit:

Nah I'm a dummy it don't do that at all.

[–] markz@suppo.fi 7 points 5 days ago (1 children)

Looks like there's just a private constructor and a public getter for the instance.

[–] bluGill@fedia.io -1 points 5 days ago (2 children)

With no indication of why we should think such a thing should be. Singletons are sometimes useful, but they are the wrong answer to your problems more often than the right one. Even where they are a good answer to your problem a class should rarely enforce its own singletonness.

[–] Mozingo@lemmy.world 8 points 5 days ago* (last edited 5 days ago)

Idk. Depends entirely on what kind of code you're writing. Singletons are extremely useful patterns for video games, for example. There should never be multiple instances of classes that handle things like game state, achievement unlocking, display/resolution managing, etc.

If they didn't enforce their own singletonness then you'd have to always launch the game using the exact same startup routines, to ensure that only one of each ever gets instantiated. But game engines typically divide the game into something like "scenes", which logically divide code and assets to only what's relevant for that area of the game. When testing a specific level/area/scene, It's extremely handy to have a singleton class exist in every scene, that acts as that startup routine, so you can start the game from any scene, and when you load in another scene through gameplay, the singleton class itself makes sure no duplicates exist, instead of having some kind of manager that keeps track of all that (which itself would also have to be a singleton, so you'd just be kicking the can down the road).

[–] drolex@sopuli.xyz 1 points 5 days ago (1 children)

Please don't make me tap the Gang of Four's Design Patterns book

[–] Feyd@programming.dev 4 points 5 days ago

That book did immeasurable damage to the software industry

[–] KoalaUnknown@lemmy.world 7 points 5 days ago (1 children)
[–] ArsonButCute@lemmy.dbzer0.com 1 points 5 days ago

Oh neat. Thank you. I was assuming Singleton was like lambda and it was returning instances of itself.

I didn't read the code very closely.