How to use the power of naming

Naming is very important in code. And I note my rule about naming.

Don't use the functional name but use the name in real world

Below code is example

    const userId = getUserId()

    const result = insertRecordA(userId)

    if(!result) {
        // Error
    }
    insertRecordB(userId)

Certainly not a problem as code. And I can understand variables and functions. However, why does it need to insert a record? Let's rewrite.

    const userId = getUserId()

    const result = reserveLesson(userId)

    if(!result) {
        // Error
    }
    addReserveHistory(userId)

Its readability become good. I can understand the purpose behind code The functional name tells us the process, but not why we need it. The best way to describe the purpose is by using the name in the real world.

Show what you're going to use it for.

Below code example

const scheduleIds = getReservationSchedule()

Although It is simple, I cannot understand what these ids are for.

Let's rewrite

const shouldCancelScheduleIds = getReservationSchedule()

It describes ids that will be used for canceling.

If the naming includes a use, we can read code easily even if code is long.

Finaly

In every code review, I tell the same thing. So, I summarized.

I hope this helps you.