Naming things is hard, but not impossible. Does anyone out there have an explicit process in deciding on names for classes, etc?
For further actions, you may consider blocking this person and/or reporting abuse
Naming things is hard, but not impossible. Does anyone out there have an explicit process in deciding on names for classes, etc?
For further actions, you may consider blocking this person and/or reporting abuse
Latest comments (48)
Hey Ben-
I just released a free mini-book about naming things. It's about how I've approached naming things in the past from a wide-variety of angles. This is more of a collection of various experiences rather than a "how-to-name-things" type book. Hopefully there's some interesting insight for everyone out there!
namingthings.donedone.com
-Ka Wai
Have you ever read this series?
Functions:
See? Does what the name says.
Variables:
const person = new Person()
Gee, i wonder whatperson
is.Objects
Methods of objects:
filereader.readfile()
. I know that it comes off the file reader object, so naming the methodreadfile
is redundant.read()
is fine.filereader.read()
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()
db.getUser(id)
util.map()
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.
I'll leave this here:
Actual branch used for a bot we're working on 😂
plural for arrays:
For Vue component gets "item" if sub components:
I try to stick with this as best as I can to keep consistancy 😅
(really need to write those somewhere...)
I generally make APIs, usually in a MVC set up, so it is relatively easy to name things. There are the entity classes and you name them under what they represent: Client, Order, Company, etc. Then, each one of them will have a service to implement the business logic for each one, so: ClientService, OrderService, etc. Then we have a controller for basically each one, then: ClientController, OrderController, etc. Methods are named under what they do, variables under they what store. Global things are generally things like authorization, database connection, configuration, etc. and they name themselves.
I don't have problems to name things and create a pattern for the names, generally it is very straightforward.
I start by karate chopping my keyboard, and then I prefix whatever that makes with ‘str_’ no matter what type it is.
I'm the one on my office that gets asked for naming help. Most of my co-workers are not native English speakers, and my mom is a school teacher, so it's in my blood.
I usually start by ask questions:
What's the business case (or who are the users)
What is the data?
What transformations are you doing?
Who are the consumers?
Then I throw out the most specific name I can muster, and usually at that point someone thinks if a new answer to the above questions that we have thought of yet. Rinse and repeat until everyone is, if not satisfied, then willing to compromise.