Retiring the Singleton Pattern, Concrete Suggestions for What to Use Instead - Pete Muldoon ACCU 21
#Programming #Cpp #AccuConf Slides: https://accu.org/conf-previous/2021/s... ACCU Website: https://www.accu.org ACCU Conference Website: https://conference.accu.org ACCU Twitter: @ACCUConf Streamed & Edited By Digital Medium Ltd: https://events.digital-medium.co.uk ------ “The worst part of this whole topic is that the people who hate singletons rarely give concrete suggestions for what to use instead.” In this talk, we will explore just such an approach for replacing the Singleton pattern in large codebases. It is easy to slip into the pattern of creating singletons - particularly in large legacy code bases - where low level functions need to propagate side effects like database updates, IPC etc. Passing parameters down long function call chains can be daunting in terms of scope of change required in a large codebase. Additionally, users calling a long established API in legacy code are frequently unwilling to change their calls to supplement the current data being passed in. After briefly reviewing a classic singleton approach to a typical problem – sending requests to a server – and it associated drawbacks. We will rework the example and replace the function's internal singleton calls with calls to an explicitly passed in wrapper class. The extra information required for legacy users is injected via a custom default instance of the wrapper so that the users of the original function require no coding changes. We will then show how the previously untestable function can now be subjected to unit testing via dependency injection. This idea is later expanded to cover keeping ABI stable dealing with non-copyable types dealing with delayed construction dealing with Singleton dependency groupings Initialization order of interdependent singletons, replacing error prone explicit intialization ordering with hard to misuse automatic initialization driven by the language. Showing how the replacement pattern can be gradually introduced to a large code base instead of 'all at once'. This alternative approach has been successfully employed in multiple areas in Bloomberg where developers believed there was no other feasible choice. ------ Pete Muldoon Pete Muldoon has been using C++ since 1991. Pete has worked in Ireland, England and the USA and is currently employed by Bloomberg. A consultant for over 20 years prior to joining Bloomberg, Peter has worked on a broad range of projects and code bases in a large number of companies both tech and finance. Such broad exposure has, over time, shown what works and what doesn't for large scale engineering projects. He's a proponent of elegant solutions and expressive code. ------ Future Conferences: ACCU 2022 Spring Conference, Bristol (UK), Marriott City Centre: 2022-04-05 to 2022-04-09. -------------------------

Practical Applications of Complexity in Software & Digital Products Development - Luca Minudel

The Single Way To Feel About The SINGLETON PATTERN

Gil Strang's Final 18.06 Linear Algebra Lecture

C++ Weekly - Live Stream 2 - Code Review

How To Think SO CLEARLY People Assume You're A Genius

Singletons in Unity (done right)

AI Is Creating A Rare Opportunity For Investors. How Jim Roppel Is Playing It. | Investing With IBD

What do tech pioneers think about the AI revolution? - The Engineers, BBC World Service

How to increase your vocabulary: Live English Class

Historian Timothy Snyder on ENDING Trump Nightmare FOR GOOD | PoliticsGirl

Don't Be Such A Singleton

Unbelievable Smart Worker & Hilarious Fails | Construction Compilation #8 #adamrose #smartworkers

The Moment That Changed Software Development!

The Death Toll From This May Exceed 10,000+...

Lisa Eckhart, ist das lustig? | Sternstunde Philosophie | SRF Kultur

Singleton Pattern (Gang of Four Design Patterns Series)

What to teach when AI writes the code | Rainer Stropek | TEDxLinz

What's the deal with the Iran deal? | feat. Lt. Col. (Ret.) Jonathan Conricus & Behnam Ben Taleblu

🩺 2024 Medical Terminology Made Easy - Part 1

