How to Name Eveything — for developers — part 2

Nikolaos Margaris
2 min readAug 16, 2020

--

We (developers) know the importance of naming variables, functions, classes e.t.c, and as we saw on ‘How to name everything — for developers — part 1

it is crucial that we establish a good pattern when naming the next most important element of our code, which is functions.

Naming Functions

We are going to use some guidelines on naming a function and not discuss about declaration or definition, or whatever input arguments and type of values should be returned from a function or method.

So here it goes…

  1. Whatever purpose a function has, it should almost always contain a verb or a preposition.

2. Be careful with reserved keyword names
i.e sort, filter, map, get, set e.t.c

3. If you don’t know where to start, then write down the first name that comes to your mind i.e function asdf(…) { … }

This is useful for people who prefer to see than to hear.

You could also revisit it later and rename it.

4. Try to follow the ‘S’ from SOLID pattern i.e Single Responsibility, and you will be faster at finding a more suitable name for your function.

5. Choose a different name for functions/methods living in the same domain (class, namespace e.t.c) with similar implementation

6. Try to reveal function’ s implementation or goal while naming it. You might also end up finding that your function does actually something different than what you really wanted it to. And that is a good thing!

7. Try to avoid full abbreviations. They are misleading most of the time. It is ok if you use partial abbreviations as soon as they are not that many inside the name or they are not close together.

8. Follow a design pattern naming.

To summarize

There are too many cases to cover when trying to name a function, and you could at least use one of the above guides to help you move on to more important and creating things which is the actual implementation and not struggle finding a good name that the rest of the developers can read, or even you after some time.

More to come on next chapter…

Sign up to discover human stories that deepen your understanding of the world.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Nikolaos Margaris
Nikolaos Margaris

Written by Nikolaos Margaris

FrontEnd Technical Lead, all-around player, experienced but also out-of-the-box thinker. ‘New’ has always something to give and ‘old’ always provides the basis.

No responses yet

Write a response