DEV Community

Maximilian Koch
Maximilian Koch

Posted on

Why you shouldn't be stingy when naming variables!

Recently I took over another project and as usual there is a bit of reading-into-it period to understand what is actually going on. It isn't a big project, but one of its classes had about 1.5K lines of code with X methods, which sometimes were very very long. In this moments I always ask myself: "Is it me or is it the layout of this class that makes it so difficult to understand?". I certainly sure about the fact that I'm not always the fast, who understands everything at once. But I think every developer has the obligation to try at least to make his or her code easily readable and understandable. Part of that is not writing looooooooong classes or even looooooooooooonger methods, but also how we name things.

I came across a lot of variables like: p, c, pc, pkAdd, etc., and I think that this is just not a good way of doing this. Sure, if you need a counter for a loop so, use c. I guess that is universal and everyone gets that. Based on that I recently posted a tweet (https://twitter.com/tschaka1904/status/984409479444824064), can you read it? :D

The point is, sometimes it is worth to write things out and use project, category, projectCategory and addProjectCategory. And surprise: Your IDE is doing almost all the magic for you 🧙‍♂️!

Keep your code r!

Top comments (0)