Lightning Talk: When C++ Singletons Fail... Richard Shepherd - C++ on Sea 2023
Вставка
- Опубліковано 12 вер 2024
- cpponsea.uk/
---
Lightning Talk: When C++ Singletons Fail... Richard Shepherd - C++ on Sea 2023
Singletons can be created uniquely, in a thread safe manner, but if there is a problem during construction, are you stuck with it?
---
Slides: github.com/phi...
Sponsored By think-cell: www.think-cell...
---
Richard Shepherd
I'm a developer and team lead for Esri's Cardiff R&D center.
---
C++ on Sea is an annual C++ and coding conference, in Folkestone, in the UK.
- Annual C++ on Sea, C++ conference: cpponsea.uk/
- 2023 Program: cpponsea.uk/20...
- Twitter: / cpponsea
---
UA-cam Videos Filmed, Edited & Optimised by Digital Medium: events.digital...
#cpp #cpponsea #cppprogramming
Singletons should be used in only very rare special cases. They are effectively global variables with all the problems that they bring. I worked for a company which used 100s of singletons and it was a complete mess! It was very difficult to maintain the code as you didn't know where the hidden singleton state might be accessed or even modified in any method you called. Also when it was decided that it was required to run multiple instances of the library a special wrapper had to be designed to handle the singletons, creating a single instance for each instantiation of the library. Effectively it was a short-sighted lazy policy to avoid passing an object as argument into each call that used it.
very good side benefit of using a pointer to hint the user to check the validity
This code was a garbage and keeped a garbage. Nothing really happens anyway. You need to remove singletons from C++ cause you do not need it in C++. Argumen is that this is an example of breaking SOLID and KISS, two responsibilities of class to exists makes this class hard to test and support, no need such complications in just once class.
C++ is an awful programming language. Just stop C++.