You make a small change. The code works, the test passes, and you move on.
Then, a few weeks later, you need to change the same behavior again. You open the file and spend longer figuring out what the code does than making the change itself. A variable has a vague name. The function handles several unrelated tasks. You find another copy of the same rule in a different folder.
That experience is common, especially when you are learning. Code can work and still be hard to maintain. By maintainable, I mean that someone can understand it, change it, and check that the change did what they intended without unnecessary guesswork.
There is no checklist that makes every piece of code easy to change. But a few habits tend to make the job harder than it needs to be. They are easy traps to fall into, not signs that you are doing programming wrong.
Five Habits That Make Future Changes Harder
| Habit | What gets harder later | A useful first step |
|---|---|---|
| Vague names | Understanding what a value or function is for | Name its role or intent |
| One function doing several jobs | Changing one behavior without affecting another | Separate steps with different responsibilities |
| Repeated logic | Fixing a rule consistently | Share code when it represents the same behavior |
| Ignored errors and edge cases | Diagnosing failures and deciding what should happen | Handle expected failure at the right boundary |
| No repeatable checks | Knowing whether a change broke existing behavior | Add a focused test or a reliable manual check |
1. Choosing names that hide intent
Names like data, temp, and process() are not always wrong. Sometimes the context makes their meaning obvious. The trouble starts when a reader has to follow several lines of code just to work out what a variable represents.
const d = orders.filter((o) => o.paid);
send(d);
What does d contain? Which orders count as paid? What does send do with them? A little more context answers those questions:
const paidOrders = orders.filter((order) => order.status === "paid");
sendReceiptEmails(paidOrders);
The clearer version is not better because it uses more characters. It is better because the names tell us what the code is trying to accomplish.
This matters when you return to code after time away, but it also helps someone reviewing your change. A name is a small explanation that stays close to the behavior. When you are unsure what to call something, describe its role in the current context. You do not need to predict every future use.
2. Letting one function take on too many jobs
A function can start with one straightforward task and gradually collect more: validate input, make a business decision, write to a database, send an email, and build a response. Each addition may seem harmless. Together, they make it harder to answer a basic question: if this behavior changes, what else might be affected?
For example, consider a function that creates an account. Checking the submitted email, saving the account, and sending a welcome message are related to the same user action, but they have different failure modes and may change for different reasons. Keeping all those decisions tangled together can make the function difficult to understand and test.
One reasonable shape is to make the main sequence visible and give a distinct step a name:
async function registerAccount(input) {
const accountDetails = validateAccountInput(input);
const account = await saveAccount(accountDetails);
await sendWelcomeEmail(account.email);
return account;
}
This is not a rule that every function must be short. A longer function can be easier to follow when its steps form one clear process. And splitting every few lines into a new function can bury the flow under a pile of names. Split code when the parts have distinct responsibilities or become easier to understand and check on their own.
3. Copying code without noticing the shared rule
Copying a few lines can be a sensible way to get unstuck. The maintenance problem appears when the copies represent the same rule, then change independently.
Imagine two screens that each decide whether a password is long enough. If the requirement changes from eight characters to ten, one screen may get updated while the other quietly keeps the old rule. Now the application behaves differently depending on where the user entered the password.
If both places genuinely need the same validation, a named helper can give the rule one home:
function isPasswordLongEnough(password) {
return password.length >= 10;
}
Both screens can call it, and a focused test can preserve the requirement. But not every similar-looking block is the same rule. A form might check a user's input while an API boundary enforces a security requirement. Combining them just because the lines look alike could make the code more confusing.
Before creating a shared helper, ask whether the behavior is actually shared and whether the helper makes that relationship clearer. Abstraction is useful when it explains the code, not just when it removes repeated text.
4. Ignoring errors and ordinary edge cases
Tutorial examples often focus on the successful path. Real programs also encounter empty results, invalid input, unavailable files, and network failures. If the code assumes every operation succeeds, the failure may appear somewhere far from its cause.
For example, a fetch call can return a response even when the server reports an error. Code that immediately parses it as a successful result misses that distinction:
async function loadProfile(userId) {
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) {
throw new Error(`Could not load profile: ${response.status}`);
}
return response.json();
}
Here, the function reports the unsuccessful response to its caller rather than pretending it has valid profile data. The caller still needs to decide what to show the user or how to recover. That decision belongs at a place with enough context to make it.
You do not need to handle every imaginable problem in every function. Start with failures that are expected at the boundary you are working with, and make the result clear. Catching an error and doing nothing with it usually makes debugging harder, not easier.
5. Skipping small tests or checks after a change
It is tempting to stop once the code appears to work. A test suite may feel like extra work when the change is small, or the feature may seem easy to verify by clicking around once.
The catch is that a working result today does not tell you whether the behavior will keep working after the next edit. A small, focused test can preserve a decision that is easy to accidentally change:
import { strict as assert } from "node:assert";
assert.equal(isPasswordLongEnough("short"), false);
assert.equal(isPasswordLongEnough("long-enough"), true);
This checks the behavior of the password rule, not the exact way the helper was written. If the code changes later, the test gives you a quick signal that the rule still holds.
Not every line needs a unit test. A test that checks an unimportant implementation detail can make refactoring harder without adding much confidence. Choose the behavior that matters, and use the smallest reliable check for it. For some changes, that may be an automated test. For a low-risk visual adjustment, a repeatable manual check may be enough.
A Small Habit for the Next Change
Before editing code, take a moment to find where the behavior starts and what relies on it. Make one coherent change, then check the relevant success and failure cases. If the code still leaves you guessing, consider whether a clearer name or a small restructuring would help the next person.
This does not need to become a ceremony. Sometimes the best change is the smallest one, with no refactor at all. The useful habit is to notice when a shortcut is creating confusion and to leave a little evidence that the intended behavior still works.
Getting Better Is Part of the Work
Maintainable code is not produced by knowing every rule in advance. Most developers learn to recognize these patterns by reading code, changing it, and seeing what made the work easier or harder.
If you recognize one of these habits in your own project, you do not need to fix everything at once. Pick the part that is making the next change difficult, improve it a little, and keep going. That is a perfectly good way to get better at writing code other people can live with.
Comments
Join the discussion on GitHub.