- read

What habits do you follow to improve your coding skills

Joseph 38

What habits do you follow to improve your coding skills

7 Code Habits to Write Better Programs

Joseph
Level Up Coding
Published in
3 min read5 hours ago

--

Writing good code is not only a skill, but also a habit. It requires discipline, consistency, and attention to detail. But how do you develop and maintain good coding habits? What are some of the best practices that can help you write better code?

In this article, I will share with you some of the habits that I stick to for writing better code.

By following these habits, you will be able to write code that is efficient, reliable, and easy to maintain. You will also improve your productivity and creativity as a coder.

1. Manually Test SQL Queries First

Running SQL manually enables validating logic and examining the execution plan beforehand. This catches schema errors, performance issues, and other problems early, before they surface in production. It also avoids hard-to-debug issues like silent query failures or slow queries impacting application performance.

Taking a few minutes per query is a worthwhile investment for engineering confidence.

I always run SQL queries manually first and check the execution plan to catch issues early:

SELECT * FROM users WHERE age > 30;

EXPLAIN SELECT * FROM users WHERE age > 30;

This avoids surprises once integrated into the code.

2. Ensure API Idempotence

Idempotent APIs prevent duplicate or unintended side effects if a client retries an operation. This is crucial for state-changing APIs dealing with finances, account settings, infrastructure configuration etc.

Not implementing idempotence can lead to subtle data corruption or inconsistencies that become nearly impossible to trace later. The peace of mind idempotence provides is well worth the extra logic.

APIs should be idempotent, especially for important operations like money transfers:

// Idempotent with unique ID
@PostMapping("/transfer")
public void transfer(@RequestBody Transfer transfer) {
// Check DB if transfer ID already processed
if (!processed(transfer.getId())) {
makeTransfer(transfer);
}
}