Footgun
2025/12/27
- Type
- Learning Resource
- Format
- Glossary Article
- Version
- General
- Subject Tags
- Created
- Updated
- 2026/02/16
- 2025/12/27
When you point a loaded gun at your feet, you risk shooting yourself.
In programming, any piece of code may have unintended consequences; but some patterns are considered "footguns": when code is written in such a way that it makes unintended behavior easy, that's a footgun.
This term is usually applied to language design decisions that affect all users of the language. All languages contain some footguns that trip even experienced programmers, because they differ from previous footguns they were used to in another language.
But you can also apply the term to code that will trip your co-workers or yourself in the future.
Generally, all APIs will contain some footguns, because it's not possible to make everything explicit using text. This is one of the limitations of text-based programming.
Here's a very basic example. Say you're making a calculator that adds two numbers. People type their numbers in a text field, and you receive text. You want to add the texts together.
@onready var line_edit_1 := $LineEdit
@onready var line_edit_2 := $LineEdit2
func add() -> void:
var number_1 := line_edit_1.text
var number_2 := line_edit_2.text
var result := number_1 + number_2
print(result)In this example, if the user entered 1 and 1, the result would be 11 instead of 2. Did you spot it?
We never transformed the text into a number. Instead, we just added the two strings.
For any experienced programmer, that isn't much of a footgun because it's expected behavior. But for beginners, it could be very tricky. How could we avoid this footgun? By making the implicit behavior explicit.
For example, some languages refuse to use the same operators for different types. You wouldn't be able to use the + operator in PHP for example. To concatenate strings, PHP uses .. You would need to write string_1 . string_2 (but then PHP allows + to append arrays...).
In general, avoid any implicit or magic behavior.
Don't stop here. Step-by-step tutorials are fun but they only take you so far.
Try one of our proven study programs to become an independent Gamedev truly capable of realizing the games you’ve always wanted to make.
Get help from peers and pros on GDQuest's Discord server!
20,000 membersJoin ServerThere are multiple ways you can join our effort to create free and open source gamedev resources that are accessible to everyone!
Sponsor this library by learning gamedev with us onGDSchool
Learn MoreImprove and build on assets or suggest edits onGithub
Contributeshare this page and talk about GDQUest onRedditYoutubeTwitter…