<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-never-write-bugs-in-c--02ocfccqj" -->

---
title: How to never write bugs in C++ | daily.dev
description: A YouTube video walks through five common C++ coding mistakes that lead to bugs: uninitialized and poorly scoped variables, not using assertions to catch...
canonical: https://daily.dev/posts/how-to-never-write-bugs-in-c--02ocfccqj
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to never write bugs in C++ | daily.dev
og:description: A YouTube video walks through five common C++ coding mistakes that lead to bugs: uninitialized and poorly scoped variables, not using assertions to catch...
og:url: https://daily.dev/posts/how-to-never-write-bugs-in-c--02ocfccqj
og:image: https://api.daily.dev/og/posts/02OCFcCqJ.png
og:image:alt: How to never write bugs in C++
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to never write bugs in C++

**[Low Level Game Dev](https://daily.dev/sources/lowlevelgamedev)** · 9 min read · 0 upvotes · 0 comments

## Summary

A YouTube video walks through five common C++ coding mistakes that lead to bugs: uninitialized and poorly scoped variables, not using assertions to catch invariant violations early, assuming file loads and external data will always succeed instead of validating them, not handling edge-case player behavior defensively (like forcing a player back inside a moving elevator), and failing to reset game state consistently between plays. The video ends with a pitch for the creator's paid C++ gamedev course covering raylib, CMake, git, and Steam publishing.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=MmAWtwmF2G8>

## Questions this post answers

### why should I always initialize variables in C++ even if I plan to assign a value right after declaring them

Uninitialized variables are a common source of subtle bugs because as a codebase grows, structs get initialized in many different places in inconsistent ways, and forgetting one path leaves garbage values in memory. Making it a habit to initialize every variable the moment it's declared removes this entire class of bug regardless of how large the project gets.

_daily.dev surfaces practical C++ habits like this for developers hardening their codebase against subtle bugs._

### what does the assert function do in C++ and does it run in release builds

The assert function checks that a condition expected to always be true actually holds, and triggers if it's false, letting a debugger break at that point to inspect the bug. Critically, assert calls are stripped out and do not execute at all in release builds, so they're useful for catching developer errors during development but won't protect or crash a shipped build.

_developers debugging C++ games can track tips like this on daily.dev while hardening release builds._

### how can I prevent a player from getting stuck outside a moving elevator in a 2D or metroidvania style game

One practical fix is to check every frame whether the player is still inside the elevator's bounds, and if they somehow escaped, forcibly reposition them back inside at the start of the frame. This guarantees the player can never exploit collision edge cases to fall out, even if the underlying physics or collision system has flaws, similar to using airbags as a backup rather than relying solely on perfect collision avoidance.

_game developers debugging edge-case physics bugs can find approaches like this curated on daily.dev._

## Similar posts on daily.dev

- [Code is Chaotic: The Art of Turning Your Game Bugs Into Features](https://daily.dev/posts/code-is-chaotic-the-art-of-turning-your-game-bugs-into-features-fhxhadztk) · Medium · 2 upvotes · 0 comments

---

Tags: [#game-development](https://daily.dev/tags/game-development), [#c++](https://daily.dev/tags/c++)

[View this post on daily.dev](https://daily.dev/posts/how-to-never-write-bugs-in-c--02ocfccqj)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to never write bugs in C++","url":"https://daily.dev/posts/how-to-never-write-bugs-in-c--02ocfccqj","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-never-write-bugs-in-c--02ocfccqj"},"datePublished":"2026-09-20T15:18:18.496Z","dateModified":"2026-09-20T15:18:41.686Z","description":"A YouTube video walks through five common C++ coding mistakes that lead to bugs: uninitialized and poorly scoped variables, not using assertions to catch...","image":"https://i.ytimg.com/vi/MmAWtwmF2G8/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/MmAWtwmF2G8/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Low Level Game Dev","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Low Level Game Dev","logo":"https://media.daily.dev/image/upload/s--Mggt4-BY--/f_auto/v1724390809/logos/lowlevelgamedev","url":"https://daily.dev/sources/lowlevelgamedev"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-never-write-bugs-in-c--02ocfccqj","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"game-development,c++","timeRequired":"PT9M","video":{"@type":"VideoObject","name":"How to never write bugs in C++","description":"A YouTube video walks through five common C++ coding mistakes that lead to bugs: uninitialized and poorly scoped variables, not using assertions to catch...","thumbnailUrl":"https://i.ytimg.com/vi/MmAWtwmF2G8/sddefault.jpg","uploadDate":"2026-09-20T15:18:18.496Z","duration":"PT9M","url":"https://api.daily.dev/r/02OCFcCqJ","embedUrl":"https://www.youtube.com/embed/MmAWtwmF2G8"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Low Level Game Dev","item":"https://daily.dev/sources/lowlevelgamedev"},{"@type":"ListItem","position":3,"name":"How to never write bugs in C++"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-never-write-bugs-in-c--02ocfccqj#faq","mainEntity":[{"@type":"Question","name":"why should I always initialize variables in C++ even if I plan to assign a value right after declaring them","acceptedAnswer":{"@type":"Answer","text":"Uninitialized variables are a common source of subtle bugs because as a codebase grows, structs get initialized in many different places in inconsistent ways, and forgetting one path leaves garbage values in memory. Making it a habit to initialize every variable the moment it's declared removes this entire class of bug regardless of how large the project gets. daily.dev surfaces practical C++ habits like this for developers hardening their codebase against subtle bugs."}},{"@type":"Question","name":"what does the assert function do in C++ and does it run in release builds","acceptedAnswer":{"@type":"Answer","text":"The assert function checks that a condition expected to always be true actually holds, and triggers if it's false, letting a debugger break at that point to inspect the bug. Critically, assert calls are stripped out and do not execute at all in release builds, so they're useful for catching developer errors during development but won't protect or crash a shipped build. developers debugging C++ games can track tips like this on daily.dev while hardening release builds."}},{"@type":"Question","name":"how can I prevent a player from getting stuck outside a moving elevator in a 2D or metroidvania style game","acceptedAnswer":{"@type":"Answer","text":"One practical fix is to check every frame whether the player is still inside the elevator's bounds, and if they somehow escaped, forcibly reposition them back inside at the start of the frame. This guarantees the player can never exploit collision edge cases to fall out, even if the underlying physics or collision system has flaws, similar to using airbags as a backup rather than relying solely on perfect collision avoidance. game developers debugging edge-case physics bugs can find approaches like this curated on daily.dev."}}]}
```

