Fundamentals 10 min read

5 Bad C++ Practices: OOP, Design Patterns, and Heap Allocation

The article critiques five common C++ misconceptions—overusing OOP, treating books as a coding substitute, obsessing over advanced language features, indiscriminately applying templates, and needlessly allocating small objects on the heap—using concrete game‑dev examples and detailed reasoning.

21CTO
21CTO
21CTO
5 Bad C++ Practices: OOP, Design Patterns, and Heap Allocation

1. Using OOP on a Cookie Clicker project

A programmer built a simple Cookie Clicker clone using classes and ended up with 50 classes, which the author argues is unreasonable for such a small project. By contrast, the author's multiplayer Minecraft clone, a far larger undertaking, also has about 50 classes. A friend rewrote the Cookie Clicker game with a few hundred lines of procedural code, making the entire codebase instantly understandable. The author recommends starting with a function and only introducing abstraction when truly needed, otherwise the OOP mindset leads to over‑designed code.

2. Replacing coding with reading books

The author likens programming to driving: learning street signs is essential, but becoming a good driver requires actual time behind the wheel. Relying on C++ books and programming‑patterns books as the primary learning method is a bad habit. Reading provides slow, often unnecessary theory, while real learning comes from tackling concrete problems in large projects. The author even calls design patterns a “scam” and argues that deep understanding emerges only after writing substantial code.

3. Spending too much time on advanced C++

The author recounts a discussion with a classmate who claimed university C++ and assembly courses were the hardest thing they ever did. While the classmate knows many languages and web development, the author spent all his time on C++, explaining why he knows more about the language. The author warns that the C++ rabbit hole is deep; focusing on esoteric quirks detracts from actual coding. He also notes that even algorithms and data structures are over‑emphasized in school, with his multiplayer Minecraft clone using only BFS as its most complex algorithm.

4. Overusing advanced C++ and templates everywhere

The author points out that modern C++ introduced many features, some of which are cumbersome. He shows a custom std::vector implementation that is far more complex than the standard one, which itself contains about 2,000 lines of code. This complexity can hide edge cases, such as a bug in MSVC’s STL related to overloaded address‑of operators. The author argues that templates and advanced features should be used only when they genuinely solve a problem; otherwise, simple C implementations are clearer and less error‑prone.

5. Randomly allocating small objects on the heap

The author observes that many beginners allocate tiny objects on the heap, believing it improves copying or prevents accidental copies—both misconceptions. He uses the analogy of taking a winter jacket into the Sahara desert and expecting a backpack to carry it; the proper solution is simply not to bring the jacket. Unnecessary heap allocation degrades performance and makes code harder to read, as excessive pointers turn code into a tangled mess. The author’s own code contains few pointers because they are only used when truly needed.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Design PatternsMemory ManagementGame DevelopmentC++OOPProgramming Practices
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.