
Don't name your variables after types:you wouldn’t name your pets “dog” or “cat” - kiyanwang
https://dave.cheney.net/2019/01/29/you-shouldnt-name-your-variables-after-their-types-for-the-same-reason-you-wouldnt-name-your-pets-dog-or-cat
======
munchbunny
I highly disagree with this advice. I understand the intent of the advice, I
just think the proposed rule (in the body of the post) is a bad implementation
of the intent because it is overly general.

Name your variable in a way that makes as clear as possible what the variable
is used for.

He uses the example of "userMap". I think its mistake is not saying what the
mapping is for. Names to users? Phone numbers to users? Emails to users? Its
mistake is not calling it a map, which tells the reader that a variable
behaves as a mapping. (And if it's not actually a map, then don't call it a
map.)

~~~
drdeadringer
> Name your variable in a way that makes as clear as possible what the
> variable is used for.

This is my consideration as well. It's like "documentation for free" or
"commenting without comments".

When I get hit by a bus tomorrow, you will be able to look at my variables and
have an easy, viable clue about what is going on. Reading my mind will be that
much easier when figuring my code.

------
klyrs
My first girlfriend named our cat named Kitty; my first spouse named our truck
Trucky and wouldn't let me name our snake Fluffy. Sometimes my variable names
reference types, but typically in dynamically typed languages. Didn't read
past the title because it's wrong about me and wrong about my code

------
tebruno99
I disagree. I don’t want to have to hunt around for the definition of users to
know how to use it. Yes the compiler will throw an error, but that doesn’t
help me when I’m typing code.

------
janpot
"Users": sounds like an array to me

"UsersMap": doesn't add much value, what are you mapping?

"UsersById": now this is my style

~~~
nickm12
Agreed. I think the article is wrong to imply that the type adds no value.
Even if you have typechecking, the names of variables help you understand
code. Also, why should we compare variables to pets versus the many other
things in our life that we do refer to by their type? I don't have proper
names for my filing cabinet or office chair.

------
romwell
Eh, my friend's cat name is exactly that -- cat.

My cat has a name, but I just call him "cat" most of the time.

The point being - if the name is not ambiguous, it's fine.

------
Jyaif
"If there is more that one *Config in scope at any one time, calling them
config1 and config2 is less descriptive than calling them original and updated
."

The correct naming is of course "originalConfig" and "updatedConfig".

~~~
eMSF
I think your proposals are still missing some sort of indication or
description on what type of configurations those variables might hold. After
all, we don't want to have any unnecessary confusion, do we?

Yeah, just 'original' and 'updated' are probably a better choice.

------
nonamenoslogan
I completely agree--having inherited a few applications worth of .NET code in
which the last (younger, right out of college) developer named all the
variables for things from Norse Mythologies.

I also inherited a bunch of circa-2005 ColdFusion with aptly named variables
in CamelCase which are much easier to understand.

varUsersTableID > pointer*Freya any day of the week.

~~~
mnorton
> developer named all the variables for things from Norse Mythologies.

this is hilarious.

------
ken
I actually had a teacher whose cat was just “cat”.

“He’s the only one. He knows I’m talking to him.”

------
gamblor956
Horrible advice unless you use an IDE which keeps track of variable types for
you.

------
coldtea
> _Don 't name your variables after types: you wouldn’t name your pets “dog”
> or “cat”_

I would if I could not tell just by looking at them what species they are (and
thus what I can do with them, what to feed them, etc) among 200 other animals
in my house.

------
defterGoose
I wouldn't name my variables "Fred" or "Noodles" either.

------
mikestew
Were my domestic pets actually amorphous blobs of text, damned straight I'd
prefix or suffix their names with "dog" or "cat" just so I could keep them
straight. "Honey, where's the header file for the blue one? Can't remember if
it gets dog food or cat food."

To torture the metaphor a bit more, of course I'd eventually remember which
one is which because they live with me. A better metaphor is the feral cat
that shows up on my doorstep once a week looking for a handout. I've slept
since then, what are you again?

------
Meph504
Firstly, I have known several people to name their animals some variation of
their type, but barring that.

I see it as a courtesy to myself than those that come after me to provide
relevant context to a variable name. If the type in the scope of the variable
is meaningful to its use then I will include it.

Good or bad code tells me what it does, rarely does it tell me what its
supposed to do.

------
CM30
Clearly the writer hasn't seen Tom and Jerry.

------
SomeHacker44
Odd. I could swear I just saw a movie with a boy and girl (human children)
named, respectively, Boy and Girl.

------
htfy96
Hungarian notation exists/existed for a reason: m_nWheels is still quite
useful in C++ program

------
maceurt
For statically typed languages yes, but for dynamically typed languages I
would say not in all scenarios.

------
ntlk
I had two mice named Mouse, and several hamsters called Hamsted, plus a guinea
pig called Guinea Pig.

------
rbanffy
I once had a cat named "dog".

~~~
LorenPechtel
Were I to get a cat (can't, my wife is afraid of them) I very well might name
it "dog" or "doggy".

~~~
codyb
"Reward for doggy" with a picture of your cat would be a great missing pet
flyer

------
shaftway
My Shiba Inu would beg to differ.

犬 = Inu = Dog

------
eznoonze
myCat1 myDog2

