Live data from Hacker News

How Developers Choose Names

arxiv.org

141–150 of 157 posts

Re: How Developers Choose Names

#141

The following article has influenced my naming choices ever since I first read it: https://www.joelonsoftware.com/2005/05/11/making-wrong-code-...

It's interesting how programmers tend to reinvent the idea of type systems after enough experience. The us_ prefix is a manually checked Us(String) type. Fortunately in modern languages we can express that at the function signature level and we don't need to spend "three weeks" training our eyes!

Re: How Developers Choose Names

#142

I just use a UUID for every variable name to make sure the codebase never has any ambiguity. No one is going to confuse e7693160-b5cf-4761-9202-de019cfd0fc9 with c3d8b9ac-d0da-4bbc-912b-025ce4e47f62

I once ported a 3rd party telecommunication middleware stack to a new OS. Every single function was 12 characters long, 4 fields of 3 characters each. Each field had meaning, but I wasn't given the decoder ring.

That was not fun.

Re: How Developers Choose Names

#143

The following article has influenced my naming choices ever since I first read it: https://www.joelonsoftware.com/2005/05/11/making-wrong-code-...

Relying on naming discipline as opposed to the more reliable features available in a language with any of (1) static typing, or (2) class-based OOP, or (3) prototypical OOP, seems...unnecessarily error-prone.

Re: How Developers Choose Names

#144

I just use a UUID for every variable name to make sure the codebase never has any ambiguity. No one is going to confuse e7693160-b5cf-4761-9202-de019cfd0fc9 with c3d8b9ac-d0da-4bbc-912b-025ce4e47f62

A good name has maximal information density. If the string is compressible, you're wasting your reader's time. That's why I use all utf-8 glyphs to render my uniformly random and highly informative (from an information theory standpoint) variable names.

A good name is also memorable, consistent, easily decipherable, and works around namespace conflicts. Might be a best 2.7 out of 4 situation, I guess. Why 2.7/4 and not 3/4? Because the remainder was lost in translation to the ASCII gods.

Re: How Developers Choose Names

#145

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.

Like other's have said, I might use "Get" to signify that this is a complex operation. Although I prefer more descriptive words like "Fetch" or "Find".

So FetchInstances() is expensive (each time it's called) but the property Instances is cheaper or only expensive on the first access.

Re: How Developers Choose Names

#146

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…

One of the worst I remember was a project which unsurprisingly was named after a game of thrones character.

I remember the era when sys admins would name machines or environments after nerdy shit like Tatooine, Dagobah. And you had to memorise which was the test environment and which was the mail server.

Thankfully I have never seen that in code.

Re: How Developers Choose Names

#147

I just use a UUID for every variable name to make sure the codebase never has any ambiguity. No one is going to confuse e7693160-b5cf-4761-9202-de019cfd0fc9 with c3d8b9ac-d0da-4bbc-912b-025ce4e47f62

Actually, you'd be really surprised about that: https://twitter.com/Foone/status/1229641258370355200

Re: How Developers Choose Names

#148

I just use a UUID for every variable name to make sure the codebase never has any ambiguity. No one is going to confuse e7693160-b5cf-4761-9202-de019cfd0fc9 with c3d8b9ac-d0da-4bbc-912b-025ce4e47f62

This implies your code has fewer than 2¹²² variables. A real coder should have more than that in each method. Sounds like you're basically a glorified VB "dev."

you're basically a glorified VB "dev."

How did you know?! Actually it's probably not far from the truth... most of the code I write is more like scripts in R & Python and small utilities than fully-fledged applications. And lots of SQL. I glue a bunch of stuff together, and after that is where my real job begins. I used to have a bit more fun writing C code to work around the limitations of an ancient ERP: that system's foundations literally extended back to before the moon landing and long before I was born.

Re: How Developers Choose Names

#150

Earlier quoted context omitted.

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.

Like other's have said, I might use "Get" to signify that this is a complex operation. Although I prefer more descriptive words like "Fetch" or "Find". So FetchInstances() is expensive (each time it's called) but the property Instances is cheaper or only expensive on the first access.

But then the name of the function is somewhat tied to its inner workings. What if you change the implementation so that it returns a cached value? To quote Michael Caine, an interface should "Be like a duck. Calm on the surface, but always paddling like the dickens underneath."
Post reply on HN