Skip to content

Commit 9420b3f

Browse files
Merge pull request #6940 from refinedev/code-comments-blog
docs(blog): change file type for blog post
2 parents 517dbcd + 7e05d6f commit 9420b3f

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

documentation/blog/2025-08-15-comments-in-code renamed to documentation/blog/2025-08-15-comments-in-code.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: 'Code Comments: The Good, The Bad, and The Hilarious'
2+
title: "Code Comments: The Good, The Bad, and The Hilarious"
33
description: A guide to writing comments that help (and avoiding the ones that hurt), with a collection of the funniest gems from real codebases.
44
slug: code-comments
55
authors: ozgur
@@ -28,7 +28,6 @@ hide_table_of_contents: false
2828

2929
---
3030

31-
3231
# Code Comments: The Good, The Bad, and The Hilarious
3332

3433
Every developer has been there. It’s 2 PM, you're deep into a feature, and you stumble upon a function named `handleData`. It takes three arguments: `x`, `y`, and `flag`. It returns `0` or `1`. There are no comments. You are now an unwilling digital archaeologist, and your afternoon is officially ruined.
@@ -46,14 +45,15 @@ Good comments don't explain **what** the code is doing; they explain **why**. If
4645
Here's where comments truly shine:
4746

4847
#### 1. Explaining the "Why" (The Business and Product Logic)
48+
4949
Code is excellent at showing the implementation, but it's terrible at capturing external context. This is the most valuable role a comment can play: bridging the gap between a business decision and a line of code.
5050

5151
```javascript
5252
// Apply a 10% holiday discount for all premium users.
5353
// This is for the Q4 campaign and must be removed after Jan 31st.
5454
// See ticket JIRA-512 for the official request from Marketing.
5555
if (user.isPremium) {
56-
price *= 0.90;
56+
price *= 0.9;
5757
}
5858
```
5959

@@ -107,7 +107,7 @@ A good comment can act as a crucial warning sign about critical, non-obvious con
107107
API_TIMEOUT = 2.5
108108
```
109109

110-
-----
110+
---
111111

112112
## The Bad: When Comments Are a Liability
113113

@@ -148,7 +148,7 @@ Developers sometimes write confusing, poorly named code and then use a comment a
148148
```javascript
149149
// This function gets the items from the database (d) and filters them
150150
// based on the user's permissions (p).
151-
function getFltItems(d, p) {
151+
function getFltItems(d, p) {
152152
// ...
153153
}
154154
```
@@ -166,9 +166,10 @@ function filterItemsByUserPermissions(items, permissions) {
166166
In the age of version control systems like Git, there is no reason to leave huge blocks of commented-out code in the codebase. It’s digital hoarding. It confuses search tools, clutters the file, and makes other developers wonder if it's important, disabled, or just forgotten. **Just delete it.** If you ever need it back, your Git history is there for you.
167167

168168
### 5\. The Rise of the AI Commentator 🤖
169+
169170
You've probably noticed that modern AI coding assistants (like Copilot or Cursor) love to add comments to almost everything they write. This isn't because they're trying to be helpful in a nuanced way; it's because they are trained on billions of lines of public code, where they've learned to associate a specific code block with a specific explanatory comment. The result is that they often produce perfectly redundant comments that explain what the code is doing, not why. The AI provides a verbose first draft, but it's still the developer's job to be the editor—to delete the noise and preserve only the comments that provide genuine insight.
170171

171-
-----
172+
---
172173

173174
## The Hilarious: Dispatches from the Codebase Trenches
174175

@@ -184,12 +185,12 @@ Every experienced developer has stumbled upon comments that are less about docum
184185

185186
```javascript
186187
// Dear maintainer:
187-
//
188+
//
188189
// Once you are done trying to 'optimize' this routine,
189190
// and have realized what a terrible mistake that was,
190191
// please increment the following counter as a warning
191192
// to the next guy:
192-
//
193+
//
193194
// total_hours_wasted_here = 42
194195
```
195196

@@ -239,21 +240,23 @@ It's bloated, confusing, and pretty awful by necessity(for the most part).
239240
*/
240241
```
241242

242-
*** And of course, when you feel too guilty ***
243+
**_ And of course, when you feel too guilty _**
244+
243245
```javascript
244246
// I'm sorry.
245247
```
246248

247249
### Linus Torvalds
248250

249-
Before finishing this blog post, I just wanted to mention Linus Torvalds, the creator of both the Linux kernel and the version control system Git. I won’t dive deep into those, since that’s not the focus here, but their rants on both reviews, and comments to code are legendarily known among the community.
251+
Before finishing this blog post, I just wanted to mention Linus Torvalds, the creator of both the Linux kernel and the version control system Git. I won’t dive deep into those, since that’s not the focus here, but their rants on both reviews, and comments to code are legendarily known among the community.
250252

251253
```javascript
252254
// Wirzenius wrote this portably, Torvalds fucked it up.
253255
```
256+
254257
If you don't know about them, I recommend googling them and their comments. Just for fun, if nothing else.
255258

256-
### Conclusion
259+
### Conclusion
257260

258261
These gems serve as a crucial reminder: code is written by people. It can be a place of pristine logic and structure, but it's also one of chaos, humor, and shared struggle.
259262

0 commit comments

Comments
 (0)