DEV Community

Discussion on: Do you have a process for naming things?

Collapse
 
ogaston profile image
Omar Gaston Chalas

My gold and confusing rule:

Be explicit according the context, but not too much

Ex.

activeOnlineUsers
activitiesMarkedAsComplete

They are "Ok", but i prefer take them into an object (JS example)

onlineUsers.active
activities.markedAsComplete

Anothers simple examples might be:

user.getName()

  • this is wrong if the user has first and last name

db.getUser(id)

  • this is wrong because you might seek the user with another param

util.map()

  • this is wrong if the util object can handle others type, not just arrays

i prefer named them like:

user.getFullName()

db.getUserById()

util.arrayMap()

Is better a long names, than a generic and inexpressive ones. But if the name is too long, is because there's something wrong in my code design.