←back to thread

178 points todsacerdoti | 7 comments | | HN request time: 0.423s | source | bottom
Show context
user-the-name ◴[] No.26340320[source]
"emplace_back"? People actually looked at this and went "Yes, this is a good function name. I understand this perfectly."?
replies(5): >>26340335 #>>26340345 #>>26340374 #>>26340547 #>>26343435 #
1. matheusmoreira ◴[] No.26340345[source]
Naming things is very hard. Wish there was away to learn how to do it better. Reading more to acquire new vocabulary? Learning latin? I'm not really sure.
replies(4): >>26340375 #>>26340811 #>>26340946 #>>26341199 #
2. johannes1234321 ◴[] No.26340375[source]
Wouldn't have that the inverse effect? - The more I know about the origin and etymology the more clever words I pick, the harder it is for the ones without that knowledge? The more trivial name might be the better one.
3. Deukhoofd ◴[] No.26340811[source]
Yeah just give everything a Latin name, your co-workers will thank you ;).
replies(1): >>26341247 #
4. user-the-name ◴[] No.26340946[source]
Don't insist on making names as short as humanly possible. Use more words. That's all it takes.
5. MauranKilom ◴[] No.26341199[source]
My stance: You start writing some piece of code and introduce e.g. a variable or a function. Then, half a minute later, you want to actually use it. You probably forgot which exact name you gave that thing. Instead of looking it up, try to come up with the name again (this time you're in the "user" perspective, not the "creator" one).

If you came up with the same name: Congratulations, you probably picked a good name!

If not: Think about how the two names you picked differ. What made you sway towards one or the other in the respective contexts? Is there some subtlety that you were not aware of earlier? Is the intention still the same? Maybe you even realize that what you wrote earlier doesn't fully do what you needed.

This also works on longer time scales and in reverse, of course. Occasionally I look at some older code I wrote and realize that, with a shifted frame of mind, I read/understand a function name the wrong way, even though it technically means the right thing too. Try to learn from these experiences as you make them and consider them when you're coming up with a name ("can this be misunderstood from the perspective of a user that is trying to do something that's only tangentially related?").

replies(1): >>26349695 #
6. matheusmoreira ◴[] No.26341247[source]
A lot of words have latin origins though. Especially scientific jargon. Greek too.
7. bombela ◴[] No.26349695[source]
I use this all the time to improve the name I picked in the first place.

But there is something I noticed: changing to a new name on the spot is more work.

I have to find all the previous occurrences and rename them.

I can use my editor to help, some plugins for it, or I can get the code to some parsable step and then do a refactor rename.

Notice how I had to get sidetracked here while I am trying to keep my original context in mind.

I use vim, so maybe I am missing out on fancier ways to do this quick on the spot rename? I would love to optimize this problem away.