Log in

No account? Create an account
Variable naming - Arvind Narayanan's journal [entries|archive|friends|userinfo]

Variable naming [Mar. 31st, 2008|07:10 pm]
Arvind Narayanan
[Current Mood |nerdy]

Am I the only programmer who is occasionally totally stumped because I can't decide what to name a variable? I mean, to the point that I have to take a break.

Variable naming is especially important to me because I use comments sparingly and believe it's better to let code document itself where possible. But surely, I can't be the only one?

[User Picture]From: smriti
2008-04-01 03:15 am (UTC)
I think it's pretty common.

I don't take breaks, but it *will* nag me from some corner of my brain, so I'll go back and rename if a better name strikes me in the next few minutes.
(Reply) (Thread)
[User Picture]From: tomtomtomtomtom
2008-04-01 03:49 am (UTC)
I knew a guy in high school who named every variable after his cats. He had a lot of cats.
(Reply) (Thread)
[User Picture]From: arvindn
2008-04-01 05:24 am (UTC)
lol, i hope he grew up to become something other than a computer programmer :)
(Reply) (Parent) (Thread)
[User Picture]From: patrickwonders
2008-04-02 12:57 pm (UTC)
There was a short period of time where all of my variable names, function names, and comments were in Esperanto.

Now, I'm definitely of the camp that a two- to three-letter variable name is fine for something that only has scope for three to five lines. So, I don't usually end up sweating variable names much. On the other hand, I often change major function names each four or five times in the first two days on a piece of code.

(Reply) (Parent) (Thread)
[User Picture]From: arvindn
2008-04-02 07:40 pm (UTC)
hey, if you're going to be in austin we could get coffee. i like randomly meeting mathematicians :)
(Reply) (Parent) (Thread)
[User Picture]From: tomtomtomtomtom
2008-04-02 07:54 pm (UTC)
super! i'll be there sometime around the 27-30 of may :)
(Reply) (Parent) (Thread)
[User Picture]From: mcfnord
2008-04-01 05:57 am (UTC)
name it something and be willing to change the name later if you think of a more accurate name.
(Reply) (Thread)
[User Picture]From: skthewimp
2008-04-01 08:20 am (UTC)
yeah has happened a LOT to me
and unlike what others here have suggested, i don't think a temporary name works. at least not for me. i usually don't like to revisit my own code.
but yeah - i don't break my head too much about it - just put some very arbit name and thus "postpone" the problem - of figuring out why i gave what name i gave.
(Reply) (Thread)
[User Picture]From: cubby_t_bear
2008-04-01 08:50 am (UTC)
What? All variables can't be named i,j,x, or a?

Clearly, I must be a math student :-P
(Reply) (Thread)
[User Picture]From: arvindn
2008-04-02 02:47 pm (UTC)
i used to do that in HS. when i ran out of names i started using 'aa' and so on. gets just a little hard when you have 20k lines of code :)
(Reply) (Parent) (Thread)
From: dykotez
2008-04-01 11:10 am (UTC)
Yeah, I do this quite a bit as well, especially with temporary variables - e.g. inside loops and stuff. I often end up calling a temporary object 'obj' or something, but it never quite sits right heh.
(Reply) (Thread)
(Deleted comment)