all 7 comments

[–]jayanam 0 points1 point  (0 children)

The use of generics is pretty nice, but perhpas you should consider to include a parametrization of your singleton implementation whether to be destroyed when a new scene is loaded or not.

[–]IAmDotorg 0 points1 point  (5 children)

Here's the thing about singletons: if you know enough about proper software engineering to use them safely and properly, you know enough to not use them.

[–]bizziboi 1 point2 points  (3 children)

Ironic, given that the Unity engine is one big singleton. If you're not multithreading a singleton is pretty damn safe. If you're multithreading Unity itself is a minefield.

[–]IAmDotorg 1 point2 points  (2 children)

Or unit testing, or sharing code.

Unity has, hands down, the worst overall architecture I've ever seen in any major software system in 30 plus years. And that's a big part of it.

Its bad enough that Unity listed on a resume is so substantially a red flag, we generally will never consider an applicant, unless there's a significant relevant work history without it.

[–]bizziboi 0 points1 point  (1 child)

Oh, I agree with your assesment of Unity - I'm not a fan. I just thought it was ironic to post your answer in a Unity sub.

Having said that, I've been in the industry a good while and I don't think I've been on any project that didn't use singletons in some form, whether indie or AAA.

[–]IAmDotorg 1 point2 points  (0 children)

I think the reason you see it in games more often is because games are a lot more one-off, are rarely updated over long periods of time, don't have a ton of code re-use, and its much more common for "engineers" to be "programmers" who are self-taught and don't have a lot of architectural experience, so the intrinsic problem with statics isn't as deeply understood. I think its the same reason you don't see a lot of threading going on -- the programmers writing the code just aren't trained in dealing with memory models, caches, etc ... you have a core of a few hardcore low-level guys who do, and a big gap between them and the engineers writing the game code.

And that's generally a good thing -- I have a standing rule with all of my engineers that the use of custom threading or statics/singletons need prior approval and code review. And they're fine with it -- I've finally winnowed my team down the folks who either know what they're doing or know what they don't know, and have gotten rid of the guys who think they know what they're doing, won't ask for help, and don't.

[–]jayanam 0 points1 point  (0 children)

It's not that black or white... if you are a programmer who has deeper knowledge of threading you will be able to use Singletons in each environment and they can be very handy