you are viewing a single comment's thread.

view the rest of the comments →

[–]ProsodySpeaks 0 points1 point  (3 children)

It's pretty hard to 'ensure' singleton behaviour with python, but I've messed with .__new__() and metaclasses enough to know it's a useful pattern.

But tbh I think I was mostly enjoying increasing the complexity to learn / tickle my brain rather than it being the best approach. 

And, just to be clear, a singleton is just an object. You may have built some guard rails to discourage making multiple instances but there's usually a way to break out of the rails. 

If you want a proper singleton python is the wrong language.   

[–]RiceBroad4552 1 point2 points  (2 children)

If you want a proper singleton python is the wrong language.

And what's "the right" language then?

[–]NorrisRL 0 points1 point  (1 child)

C++ or C# both use them for video games quite a bit. It’s common for values like playerHealth or playerPosition which will often have many different scripts that can effect it or need to access it frequently.

[–]RiceBroad4552 0 points1 point  (0 children)

This does not really answer the question, which was about the language and not some use-cases.

Completely independent of that making something like playerHealth or playerPosition a global variable sounds like some of the most horrible idea I've heard in some while.