Programming: Naming

Where are you talking from?

A tiger labelled “danger zebra”
This is what happens when you replace abstractions with descriptions. But you must make sure that “Snow tiger” is well defined in you project’s dictionary.

What is programming?

Your audience is not the machine

You’re not speaking

Writing for the unknown

What to name?

How to name?

Take time

In 2013 a discussion thread on Quora led to discover that naming things was the hardest task for half of programmers.

There are only two hard things in Computer Science: cache invalidation and naming things .

Add value

x1 = getUnitPrice()
x2 = getCount()
// You’ll have to find the origin of x1 and x2 to
// understand what "total" is
total = x1 * x2
up = getUnitPrice()
c = getCount()
// Is "up" the opposite of "down" ?
// Is "c" the speed of light?
total = up * c

State the what, not the how

eventsArrayMap: Map<User, Event[]>
eventsByUser: Map<User, Event[]>
userHistories: Map<User, Event[]>

Be specific


Avoid local duplicates

unitPrice = getUnitPrice()
quantity = getCount()
function computeTotal (unitPrice, quantity) {
return unitPrice * quantity // Which ones?
total = computeTotal(unitPrice, quantity)

Avoid isolated duplicates

class Block { 
contents: string
note: string
class Note {
title: string
blocks: Block[]

Be consistent

Be shareable

Files and directories

Be exact

Don’t re-state context

class House {
houseDoor: Door // redundant
var house = new House()
var houseDoor = house.houseDoor
class House {
door: Door
var house = new House()
var houseDoor = house.door


// Models collection
models: Model[]
modelList: Model[]
// Models dictionary
modelByKey: {[key: string]: Model}
// The versions of a model
modelVersions: Version[]
// The versions of models
modelsVersions: {[model]: Version[]}

Beyond names

If comments re-state the name, rewrite or remove the comment.


Software engineer for three decades, I would like to share my memory.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store