Avoid defective nouns when naming things

Naming things is hard

You always have to keep in mind, software developers spend more time reading source code than actually writing it. A lot of other people will someday read the source code you are writing today. Better make sure to write it clear, consistent, and well structured. I can recommend reading Clean Code by Robert C. Martin.

Naming things is one part of writing clean code and often it is quite hard to find the right names. In the following, I just want to show you one easy step to improve your source code.

Avoid defective nouns

Defective nouns are nouns without singulars, nouns without plurals, or nouns that have the same singular and plural (e. g. information, music, or news). See Wikipedia for more details.

Usually, in software development, you will need a noun that differs in singular and plural. So you are well-advised not to use defective nouns.

Example

Think about the list of posts on DEV. How would you name those? There are multiple options, but you should definitely avoid a defective noun.

❌ Wrong: newss/news

newss.forEach(function(news) {
    news.doSomething();
});

❌ Wrong: newsList/news

newsList.forEach(function(news) {
    news.doSomething();
});

❌ Wrong: news/singleNews

news.forEach(function(singleNews) {
    currentNews.doSomething();
});

✅ Correct: posts/post

posts.forEach(function(post) {
    post.doSomething();
});

Bonus: Irregular plural nouns

I will tell you a little secret. This might be a bit fussy, but I try to avoid irregular plural nouns, too. I do not like medium and media, child and children, or radius and radii. I just like good ol' regular plural nouns like post and posts, user and users, list and lists.

Malte Riechmann

New git guidelines: We have switched to Conventional Commits

Giving teams as much autonomy as possible is a good idea, but having some company-wide guidelines can...

Discover full article

Cleo Pelte

One year of coding – recommendations for beginners from a beginner

This month one year ago I started my three year long journey as a web development trainee/apprentice...

Discover full article

Malte Riechmann

Our tech stack in 2022

Preface Reading about our tech stack from one year ago gives me confidence for the future....

Discover full article
View all articles

Right on the intersection of communication, marketing and digital product development »visuellverstehen« offers innovative solutions and concepts for all areas of corporate communication. No matter if you are a mid tier business, an established brand, a cultural institution, an industrial corporation or a successful trading company we advice and accompany you holistically and honestly.