user2472173
user2472173

Reputation: 43

Fancy Code Comments In Intellij IDEA

I was browsing through a fellow devs code on GitHub when I recognized centered comments. At first I thought someone felt like making a really nice and fancy comment today, then I realized they were used across the project.

Here’s an example of what I’ve seen:

    /*
     * =============================================================
     * ================ WORLD CREATION AND LOADING =================
     * =============================================================
     */

I asked around the dev chat and no one seemed to know where it came from. Could somebody please tell me if it’s possible to reformat all comments to look like this, or possibly add it as a formatter in an IDE (IntelIj).

Upvotes: 2

Views: 1365

Answers (1)

dkatzel
dkatzel

Reputation: 31648

While it looks nice, I think needing a comment like this is a code smell.

Comment blocks like these imply that you have very long methods that do too many things and each subsection needs an explanation on what the heck it is doing.

I once refactored a legacy project I inherited where I converted all the block comments that looked like this into their own methods. The new methods were named in an intent revealing way derived from the original comment. This way, I could add more explanatory javadoc to better explain what was going on in the block of code.

For example I would take this code and refactor it into either:

createAndLoadWorld(...);

Or

World world = create(....);
load(world);

Now you get the added benefit of having easier to test code since you can test the methods in isolation or mock them out.

Upvotes: 5

Related Questions