Kenresoft Technologies Ltd
Discuss a projectLog in
Back to Insights
Software DevelopmentApril 26, 20238 min readKenneth Amadi

Do Developers Really Need to Comment and Document Their Code?

Discover why writing code comments and project documentation matters, how they differ, and practical best practices for leaving meaningful context for your future self and team.

Code QualityDocumentationProgrammingBest PracticesClean Code
Do Developers Really Need to Comment and Document Their Code?

One question that crosses the mind of many developers, especially when they're starting out, is whether they really need to spend time commenting and documenting their code.

When you're trying to get an application working, documentation can feel like extra work.

You have a feature to finish. There is a bug to fix. The deadline is approaching. The code works, so why spend another 30 minutes explaining it?

I used to think about it that way too.

Earlier in my programming journey, I worked on several projects without paying much attention to comments or documentation. I was focused on building features and getting things working.

At the time, it didn't seem like a problem.

Until I returned to some of those projects much later.

I could still recognize the code I had written, but understanding some of the decisions behind it was surprisingly difficult. I knew what the code was doing, but I couldn't always remember why I had implemented it that way.

That experience changed how I think about comments and documentation.

Working Code Isn't the Whole Story

Writing software is, fundamentally, about solving problems.

We use programming languages to turn those solutions into something a computer can execute. But as an application grows, the codebase can become increasingly difficult to understand and maintain.

A project that starts with a few files can eventually contain hundreds or thousands of them.

A developer who initially worked alone might eventually be joined by several others.

And the person maintaining the code six months from now might not be the same person who wrote it today.

Sometimes, that person is you.

This is where maintainability becomes important.

Code doesn't only need to work. It needs to be understandable enough that someone can safely change it later.

That doesn't mean every line needs a comment.

It means we should leave enough context behind for the next person who has to work with the code.

Comments and Documentation Are Different

One thing that is often overlooked is that code comments and documentation aren't the same thing.

They serve different purposes.

Comments explain something close to the code

Comments are useful when the reason behind an implementation isn't obvious.

For example:

Dart
// Keep the cached response because this endpoint is rate-limited
// and the data only changes periodically.
final result = await cache.get(key);

The comment isn't explaining what cache.get() does.

The code already tells us that.

Instead, it explains why we're using the cache in this particular situation.

That's the kind of information that can be difficult to recover by simply reading the code.

A less useful comment would be:

Dart
// Get the cached result
final result = await cache.get(key);

It doesn't really tell us anything we couldn't already see.

A useful rule is:

Comments should provide context, not simply translate code into English.

Documentation explains the bigger picture

Documentation operates at a different level.

It can explain:

  • What a project does

  • How to install and configure it

  • How the architecture is organized

  • How to use an API

  • How authentication works

  • Required environment variables

  • How to deploy the application

  • Common workflows

  • Configuration options

  • Examples

  • Known limitations

  • Migration and upgrade procedures

If a developer has to read through the entire source code just to figure out how to run your project, the project probably needs better documentation.

When Are Comments Actually Useful?

Comments can be useful for several things, including:

1. Explaining why something was implemented a particular way

This is probably one of the most valuable uses of comments.

Sometimes there are several ways to implement something, but there is a specific reason you chose one approach.

That reason may not be obvious from the code.

Document it.

2. Explaining work that still needs to be done

A TODO comment can be useful when it provides enough context.

Instead of:

Dart
// TODO: Fix this

something like this is more useful:

Dart
// TODO: Replace polling with webhooks once the provider
// supports transaction status callbacks.

Now another developer knows what the problem is and what the intended solution looks like.

For larger pieces of work, however, an issue tracker is usually a better place than a TODO comment buried inside the code.

3. Documenting workarounds

Sometimes you have to write code that looks unusual because an external service, framework, platform, or library has a limitation.

Without an explanation, another developer may "clean up" the code later and accidentally reintroduce the original problem.

A short comment can prevent that.

4. Pointing out important performance or compatibility considerations

If a particular implementation exists because of a performance constraint, platform difference, or compatibility issue, document that reasoning.

Again, the important information is usually why, not what.

But Don't Comment Code Just for the Sake of Commenting

There is also such a thing as too many comments.

Consider this:

Dart
// Increment the counter
counter++;

The comment doesn't help.

The code is already obvious.

If you constantly need comments to explain simple code, the underlying code may need improvement instead.

For example, compare:

Dart
if (user.role == 'admin' || user.role == 'owner') {
  ...
}

with:

Dart
if (user.canManageSettings) {
  ...
}

The second version communicates intent through the code itself.

No additional comment is necessary.

This is why good naming and clear structure are so important.

The first solution to unclear code should often be clearer code—not another comment.

Documentation Is More Than Comments

Documentation becomes particularly important when you're building software for other developers.

If you're publishing a package, library, framework, SDK, API, or developer tool, the documentation is part of the product.

A developer using your package shouldn't have to reverse-engineer the source code to figure out how to get started.

At minimum, useful project documentation should answer questions such as:

What is this?

What problem does the software solve?

How do I install it?

What are the prerequisites and installation steps?

How do I use it?

Show a simple working example.

How does it work?

Explain important architecture or concepts where necessary.

What configuration does it require?

Document environment variables, configuration files, API keys, and other requirements.

What are the limitations?

If something doesn't work in a particular environment or has an important restriction, say so.

These things save developers from having to discover everything through trial and error.

Your README Is Documentation Too

Documentation doesn't always have to be a separate website.

For many projects, the README is the first and most important piece of documentation someone will see.

A good README can provide:

Project overview
Installation
Configuration
Quick start
Usage examples
Development setup
Testing
Deployment
Contributing
License

You don't necessarily need every section for every project.

The important thing is to give readers enough information to understand the project and get started without unnecessary friction.

Document Decisions, Not Just Instructions

One area where documentation becomes particularly valuable is architectural decisions.

Imagine you join a project and discover that a particular API request is deliberately cached for ten minutes.

You can see what the code is doing.

But you don't know why.

Was it done for performance?

Was the API rate-limited?

Does the data only change every ten minutes?

Was there a production incident that led to this decision?

That context can matter more than the implementation itself.

This is why documenting important decisions is valuable.

You aren't just documenting the code.

You're documenting the reasoning behind the system.

Documentation Doesn't Have to Be Perfect

Another mistake developers make is thinking documentation has to be comprehensive before it is worth writing.

It doesn't.

A useful README is better than no README.

A short explanation of an architectural decision is better than leaving the next developer to guess.

A few good examples are better than a huge page that nobody wants to read.

The goal isn't to document every possible detail.

The goal is to document the details that someone is likely to need.

Write It While You Still Remember

One of the biggest lessons I've learned is that documentation becomes much harder when you leave it until the end.

When you've just solved a complicated problem, the reasoning is still fresh.

You remember:

  • Why you chose the approach

  • What alternatives you considered

  • What problems you encountered

  • Which limitations you discovered

  • What future improvements are needed

A few months later, you may remember none of it.

So when something important happens during development, document it while the context is still fresh.

It doesn't have to be a long document.

Sometimes a few sentences are enough.

The Future You Is Also a Developer

When you're working on a project today, it's easy to think only about the current team.

But software has a much longer lifespan than the moment it was written.

Someone else may maintain it later.

A new developer may join the team.

The project may be handed over to another company.

Or you may come back to it yourself after months away.

That future developer doesn't have the context you have today.

They only have the code and whatever information you decided to leave behind.

I've experienced this personally.

Some of the projects I built earlier in my programming journey made perfect sense while I was actively working on them. Coming back later was a different story.

That experience taught me something simple:

Write code for the computer, but leave enough context for the humans who will maintain it.

So, Should You Comment and Document Your Code?

Yes—but not blindly.

Don't turn every function into a collection of comments explaining things that the code already makes obvious.

Instead:

  • Write clear and meaningful code.

  • Use names that communicate intent.

  • Keep functions and classes reasonably focused.

  • Comment the why when it isn't obvious.

  • Document important architectural decisions.

  • Keep your README useful.

  • Document APIs and public interfaces.

  • Explain configuration and setup.

  • Record important limitations and workarounds.

  • Remove outdated comments when the code changes.

  • Keep documentation close to the codebase when appropriate.

The goal isn't to write more documentation.

The goal is to leave behind useful context.

Because the code you write today may eventually be maintained by someone who wasn't there when you wrote it.

And sometimes, that person will be you.

Your future self will appreciate the explanation.

About Kenresoft

Kenresoft is a software engineering company. We build web and mobile applications, backend systems, APIs and developer tools, including Kenresoft CMS.

About Kenresoft

Let's talk

Have a system to build or fix?

If you have a product idea or a technical problem without a good answer yet, tell us about it.