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.

Julia Lange

Access Current Entry in Custom Validation Rule

Sometimes, when writing a custom validation rule for a Statamic project, I find myself in a position...

Discover full article

Lakkes

Create an entry approval workflow with Statamic Revisions

When managing entries in your Statamic application that gather external data, such as from APIs, you...

Discover full article

Yamen Hadla

Effortless Language Redirection - TYPO3 Extension

Introduction Hello fellow TYPO3 enthusiasts! I had the pleasure of cooperating with my...

Discover full article
View all articles