Site icon Being Software Craftsman (DFTBA)

Naming functions or methods

Photo by Markus Spiske on Unsplash

I will show you bad and good naming of methods with the help of some code examples. Let’s see some of the typical functions related code smells on a case by case basis.


Smells —

Abbreviations

Not doing what it says

Use of nouns instead of verbs in method names

Noisy words

Why are you adding noisy/redundant words like Info, Details, Information in front of appointment? In my opinion, getAppointment() gives us information about the appointment. Keep it simple.

Further,

Just getStudents() make sense to me. You don’t need to tell your audience about how’s your implementation under the hood.

Not symmetric

If you are adding symmetric methods, then make sure they feel symmetric one.

Not having descriptive/searchable names

One word per concept

Why are you using different words (fetch, retrieve, get) for the same concept? Just choose one word per concept and use it throughout your project.

Side effects

Look for anti-patterns:`And`, `Or`, `If`.

Command and query in one function


The guidelines for naming methods:


Exit mobile version