Turn code comments into friendly log messages

Great comments explain “why” code does something rather than “how” things are done.

Great comments explain unidiomatic code.

Great comments dispel confusion, not cause it.

But have you ever considered turning great comments into a log message?

Comments transformed into log messages are friendly debugging statements.

They help to understand the runtime behavior of your application.

For non-critical logs, just use the DEBUG or TRACE log level.

Next time you see a useful comment, consider to just turn it into a log statement.

// Before
if (targetTableExists()) {
    // Skip data base migration because the target table `animals_v2` already exists.
    return false;
}

// After
if (targetTableExists()) {
    log.trace("Skipping data base migration because the target table `{}` already exists", TARGET_TABLE);
    return false;
}
Active vs passive software development
Older post

Active vs passive software development

When software developers enter in management positions, they are often lacking to not code actively. In this article I argue that passive software development through delegation is indeed a valuable exercise. It still makes you a better developer.

Newer post

Be that good ancestor

Legacy code is often associated with being something bad. However, legacy software is often a valuable asset for businesses. When touching legacy code with the due respect it deserves, it ultimately leads to tough questions: will we ourselves be that good ancestor to others?

Be that good ancestor