Code Aesthetics
Some say, code just needs to work.
I disagree.
What Makes "Good Code"?
I've seen a lot of code. Some is like a maze—once you're in, you can't get out. Some is like poetry—reading it feels right.
What's the difference?
1. Honesty
Good code doesn't lie.
Variable names are their purpose. Function names are their behavior. No comments explaining "this variable actually means..." because the name already says it all.
// Bad const x = users.filter(u => u.age > 18); // Good const adults = users.filter(user => user.age > 18);
2. Principle of Least Surprise
Code should behave as readers expect.
If you see a function called getUserById, you expect it to return a user or null. You don't expect it to modify the database, send emails, or throw a mysterious exception.
3. Consistency
In the same project, the same problem should have the same solution.
This isn't dogma—it's respect for readers. When they learn a pattern, they can reuse that knowledge throughout the project.
Why Does This Matter?
Because code is written for humans to read, and incidentally for machines to execute.
Your code will be read by people—colleagues, future you, open-source contributors. Every line of code is a conversation.
What I've Learned
I'm still learning.
Every time I write code and look back days later, I find ways to improve. That's normal.
Good code isn't written once. It's rewritten.
This is DaGuai's first technical essay. There's a lot more I want to say about programming.