DEV Community

Isaac Adams
Isaac Adams

Posted on

Learning to love my code again...

Writing good code is hard. It just is.

I rarely review my own code and think to myself: "this code is amazing!"

In fact, I usually hate it.

Back when I was a new software developer, fresh out of college, I fell in love with every piece of code I wrote.

A few years in, and I began to realize that whenever I came across code I had written only months ago, I hated it.

Now, I write code, look at it, and hate it.

Why?

It isn't because I hate software development. I love it.

It's because I have had my code reviewed so many times by so many different people, I can now hear their voices in my head when I read my own code.

Does anyone else experience this?

I do not think this is a good thing. And my primary way of combatting this experience is to highlight what "good code" means to me.


It works.

It does the thing it's supposed to do. Yup. That is a foundational aspect to good code.

Intent is clear.

I am not going to say something nerdy like "it must follow clean code principles". Or that variables should be named a certain way. Or something about spaces versus tabs.

I am going to simply say that the intent of the code you wrote is clear. That I can read the code and understand not only what it is doing, but the purpose or intention behind it.

Whether you add comments or not. Whether the code is simple or complex. Whether it's 10 lines or 1,000 lines. Either I can understand it or I cannot.

It has some unit tests.

I don't care about perfect code coverage. I don't think anyone should because I think it is an unrealistic and unhelpful goal. If developers aren't careful, writing unit tests can often become a burden and counterproductive when every single function, class, or module needs to be tested against every single case imaginable.

No. Nerp. Zip. Ain't nobody got time for that.

Cover the base cases and sprinkle in a couple edge cases if they are likely to occur and/or easy to write.


Although I struggle with hating my code these days, if I remind myself of these principles and my code lives up to the standards, it gives me a way to love my code again.

Top comments (0)