Why I Don't Like Singletons
The Cherno
View ChannelAbout
Yan Chernikov - I'm making a game engine called Hazel! Here you'll find videos about that and C++/programming. For professional inquiries, please send an email to [email protected]
Latest Posts
Video Description
To try everything Brilliant has to offer—free—for a full 30 days, visit https://brilliant.org/TheCherno . You’ll also get 20% off an annual premium subscription. Patreon ► https://patreon.com/thecherno Instagram ► https://instagram.com/thecherno Twitter ► https://twitter.com/thecherno Discord ► https://discord.gg/thecherno 🔗 LINKS Meyers' Singleton ► https://laristra.github.io/flecsi/src/developer-guide/patterns/meyers_singleton.html Radar Contact code ► https://github.com/Bogdanctx/Radar-Contact Hazel ► https://hazelengine.com 🕹️ Play our latest game FREE (made in Hazel!) ► https://studiocherno.itch.io/dichotomy 🌏 Need web hosting? ► https://hostinger.com/cherno 📚 CHAPTERS 0:00 - Comments and the Community 3:41 - The Comment 4:52 - Singletons and Context 8:47 - Lazy Loading 10:35 - Why are singletons "bad"? 15:51 - Having a "global variable" is "better" 16:23 - Reviewing Meyers' Singleton 19:38 - Improving our singleton to make shutdown explicit 21:11 - Not storing our instance in static storage 22:56 - Removing lazy loading to make initialization explicit 23:47 - The "global" situation - my solution 💰 Links to stuff I use: ⌨ Keyboard ► https://geni.us/T2J7 🐭 Mouse ► https://geni.us/BuY7 💻 Monitors ► https://geni.us/wZFSwSK This video is sponsored by Brilliant.
Upgrade Your Coding Setup
AI-recommended products based on this video

Dell UltraSharp 24 Monitor - U2424H

Dell UltraSharp U2723QE 27" 4K UHD WLED LCD Monitor - 16:9 - Black, Silver EPEAT

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

Logitech G305 LIGHTSPEED Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Anker 332 USB-C Hub (5-in-1) with 4K HDMI Display, 5Gbps - and 2 5Gbps USB-A Data Ports and for MacBook Pro, MacBook Air, Dell XPS, Lenovo Thinkpad, HP Laptops and More

Logitech K250 Bluetooth Keyboard with Numpad, Easy Connectivity, Compact Wireless Keyboard Made with Recycled Plastic, Spill-Resistant, Comfortable Keys - Windows/MacOS - Graphite

Logitech K400 Plus Wireless Touch TV Keyboard With Easy Media Control and Built-in Touchpad, HTPC Keyboard for PC-connected TV, Windows, Android, Chrome OS, Laptop, Tablet - Black

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

Logitech G305 LIGHTSPEED Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Laptop Sleeve Case 11–14 Inch MacBook Air MacBook Pro Surface Laptop Dell XPS 13 HP Envy Pavilion Lenovo Yoga Slim IdeaPad Acer Swift Chromebook Samsung Galaxy Book Shockproof Leather Bag Colour Blue

Gumdrop ProTech Case for Dell New XPS 13 Plus 9320 Laptop- Slim Lightweight Case with Energy Displacement Protection, Non-Skid Rubber Feet and Frosted Exterior for Bumps and Drops (Black)

65W 45W USB C Laptop Charger Compatible with Dell Latitude 5420 5430 5520 5530 7340 7430 Inspiron 14 16 XPS 13 Chromebook 3100 Dell Computer Type C Fast Charging AC Adapter Power Cord

45W 65W AC Adapter Laptop Charger for Dell Inspiron 15 14 13 17 3000 5000 7000 Series 5558 5559 Charger Latitude E6440 E6430 3520 3420 XPS 13 14 9333 9350 Notebook Dell Computer Power Supply Cord

Corsair CP-9020140-UK HX1200 1200 W 80+ Platinum Fully Modular Power Supply Unit - Black

Corsair RM1000e Fully Modular Low-Noise ATX Power Supply - Dual EPS12V Connectors - 105°C-Rated Capacitors - 80 Plus Gold Efficiency - Modern Standby Support - Black

Corsair SF1000 (2024) Fully Modular Low Noise 80 Plus Platinum ATX Power Supply – ATX 3.1 Compliant – PCIe 5.1 Ready – SFX-to-ATX Bracket Included – Black

Corsair HX1200i (2025) Fully Modular Ultra-Low Noise ATX Power Supply with 12V-2x6 Cable – ATX 3.1 & PCIe 5.1 Compliant, Cybenetics Platinum Efficiency, Fluid Dynamic Bearing Fan – Black

Crucial T705 4TB PCIe Gen5 NVMe M.2 SSD - Up to 14,100 MB/s - Game Ready - Internal Solid State Drive (PC) - +1mo Adobe CC - CT4000T705SSD3

Crucial X9 4TB Portable SSD, Up to 1050MB/s, USB 3.2 USB-C, External Solid State Drive, Compatible with Windows, Mac, & Android, Reliable Storage for Games, Files, & Backups, Black - CT4000X9SSD902

Crucial X10 Pro 4TB Portable SSD, Up to 2100MB/s Read, 2000MB/s Write, 3.2 USB-C, External Solid State Drive, Durable Storage for PC & Mac, for Professional Creators, Black - CT4000X10PROSSD902

Crucial X9 Pro 4TB Portable SSD, Up to 1050MB/s Read & Write, 3.2 USB-C, External Solid State Drive, Durable Storage for PC and Mac, for Professional Creators, Silver - CT4000X9PROSSD902

Portable Air Conditioners, wobuzhi Evaporative Air Cooler with LCD Screen, Fan Speed&Spray, 7 RGB Lights,USB Powered,1-8H Timer, Personal Air Conditioners, Portable Air Conditioners for Home Office

llano RGB Laptop Cooling Pad with Powerful Turbofan Gaming Cooler Radiator with Infinitely Variable Speed, Touch Control, LCD Screen, 3-Port USB Hub, Seal Foam for Notebook Computer 15-19in

Neck Fan with Cooling Plate,Portable Neck Fan Rechargeable Battery Powered,Bladeless Personal Air Conditioner Wearable Neck Cooler Fans,USB Electric Quiet Necklace AC Fans for Travel Outdoor Black




