Live data from Hacker News

How Developers Choose Names

arxiv.org

101–110 of 157 posts

Re: How Developers Choose Names

#101

As a non native english speaker I have a recurring problem with this: > getInstances(); // ok, returns an array of instances > getInstanceId(); // ok, returns an id > getInstancesId(); // ??, returns an array of id > get InstancesIds(); // ?? returns an array of id > getIdsOfInstances(); // ?? returns an array of id > getAllInstancesId(); // ?? returns an array of id > getAllInstancesIds(); // ?? returns an array of…

As a native English speaker (and former English teacher), hope this helps: > getInstances(); // ok, returns an array of instances Correct. > getInstanceId(); // ok, returns an id Correct. > getInstancesId(); // ??, returns an array of id Unusual, but would return a single ID referring to a collection of instances. > get InstancesIds(); // ?? returns an array of id Correct. Though more common would be getInstanceIds()…

One thing that getInstancesIds() might mean is "get the (multiple) ids for each of multiple instances".

I don't know why an instance would have more than one id, probably more plausible with different nouns, but a similarly named function might return an array of arrays, or a flattened equivalent, possibly uniqued.

Probably a bad idea though. I have been guilty (though pleasurably, pridefully guilty) of abusing plurals -- day, days, dayses etc. If you can let the types do the talking that's obviously better, and more descriptive (and less eccentric) names can help a lot with communication and clarity, but there is also sometimes a place for brevity, and for levity.

Re: How Developers Choose Names

#102
This reminds me of this old quote from qotd: We had fairly random naming for our servers, so I proposed we named them after planets - and the admin responded with "great idea, you mean like planet01, planet02, planet03.."

It´s a funny story, but naming means ALOT when you are developing, or building systems or processes that requires a name or an identificator.

Also don´t be afraid of changing the name if it no longer reflects on its purpose.

Re: How Developers Choose Names

#103

As a non native english speaker I have a recurring problem with this: > getInstances(); // ok, returns an array of instances > getInstanceId(); // ok, returns an id > getInstancesId(); // ??, returns an array of id > get InstancesIds(); // ?? returns an array of id > getIdsOfInstances(); // ?? returns an array of id > getAllInstancesId(); // ?? returns an array of id > getAllInstancesIds(); // ?? returns an array of…

I have never understood the practice of using a verb phrase ("get") for functions with no side-effects. To me it makes more sense to name the function after the result, i.e. Instances, InstanceIds, AllInstanceIds etc.

Re: How Developers Choose Names

#104
very badly, sometimes randomly, magic 8 ball

would not be surprised if some dev somewhere considered naming his/hers first born "/tmp/first_born" until coming up with a better name

we can also add mathematicians and physicists to the group of people that are exceptionaly bad at naming stuff

Re: How Developers Choose Names

#105

As a non native english speaker I have a recurring problem with this: > getInstances(); // ok, returns an array of instances > getInstanceId(); // ok, returns an id > getInstancesId(); // ??, returns an array of id > get InstancesIds(); // ?? returns an array of id > getIdsOfInstances(); // ?? returns an array of id > getAllInstancesId(); // ?? returns an array of id > getAllInstancesIds(); // ?? returns an array of…

I have never understood the practice of using a verb phrase ("get") for functions with no side-effects. To me it makes more sense to name the function after the result, i.e. Instances , InstanceIds , AllInstanceIds etc.

Preforming I/O is a side effect. Accessing an external database is a side effect. Using a verb to imply external access to "get" some resource is appropriate in this instance.

Re: How Developers Choose Names

#106
post #104

very badly, sometimes randomly, magic 8 ball would not be surprised if some dev somewhere considered naming his/hers first born "/tmp/first_born" until coming up with a better name we can also add mathematicians and physicists to the group of people that are exceptionaly bad at naming stuff

Primo is an actual name in Italian; the others have fallen (more) out of fashion, but certainly Quintus, Septimus and so on used to be perfectly reasonable Latin names.

Re: How Developers Choose Names

#107

With naming what IMO matters more than choosing one name, is choosing a name that is consistent with other similar names in the codebase. A new developer will learn your project's specific convention in a few minutes, but will be completely lost if the convention is routinely violated here and there. This is especially important with what verbs to use in methods, and how to name interfaces/classes in a way that respe…

Naming gets far worse than that. I've worked on code where the naming was not just unhelpful, it was outright misleading. One of the worst I remember was a project which unsurprisingly was named after a game of thrones character. As I never watched game of thrones it took me about two weeks before I could even remember the stupid name, during which time I was also dumbfounded as to how the program worked until I real…

When I was working on a small game startup back 20 years ago, I renamed our all the high-level projects of our codebase into specifically-ancient Greek and then left a "glossary.txt" in the root directory so people could brush up on their language skills... this did not last for very long ;P.

Re: How Developers Choose Names

#108

Earlier quoted context omitted.

If you don't have refactoring that can rename functions across your code base, now you have two problems

In 16 years as a developer, I have never seen this beyond the scope of a single project/language. Once things cross boundaries it stops.

What boundary would be involved in the handleClick example? Or are you speaking more generally about renames across API contracts?

Re: How Developers Choose Names

#109
post #58

Earlier quoted context omitted.

I’m an engineering lead and I made a rule of using the handleClick() style instead of updateDate() in our codebase. The reasoning is that the latter sounds more like an atomic, standalone function, whereas handleClick() may have some internal checks that could eventually call something like updateDate(), but the internal checks are beyond the responsibility of the updateDate() function.

I agree. It's also nice to know when you see a `handle` function, it is getting slotted into an `on` somewhere. Within the handle I prefer to call functions such as updateDate(). But this whole thread brings up something about coding that has always irked me, it's very opinion based. When two people strongly hold the opposite opinions on the same team, it can be a massive hassle for absolutely zero benefit.

When two people strongly hold the opposite opinions on the same team, it can be a massive hassle for absolutely zero benefit.

On teams, or in life in general, IMO when there is no consensus, or even an anti-consensus, the only rational global decision is not to make a global decision.

Re: How Developers Choose Names

#110

As a non native english speaker I have a recurring problem with this: > getInstances(); // ok, returns an array of instances > getInstanceId(); // ok, returns an id > getInstancesId(); // ??, returns an array of id > get InstancesIds(); // ?? returns an array of id > getIdsOfInstances(); // ?? returns an array of id > getAllInstancesId(); // ?? returns an array of id > getAllInstancesIds(); // ?? returns an array of…

I have never understood the practice of using a verb phrase ("get") for functions with no side-effects. To me it makes more sense to name the function after the result, i.e. Instances , InstanceIds , AllInstanceIds etc.

The advice I once got and since internalized is to reserve 'getX' to give a hint that something happens besides returning 'X', lazy initialization is a common use case.
Post reply on HN