Question:
Is there a convention among programmers for how to name temporary variables?
Johnny
2010-03-11 21:47:37 UTC
My tutor keeps telling me to rename stuff ( like class / array names etc ) because it wouldn't make sense to other programmers. He says that there's really standardized ways of naming / organizing certain things in source code.

Is there a 'proper' way to name the temporary versions of variables ( for example I'm using temporary variables in the arguments of constructors and stuff )

I've been using temporary_VariableName but it's a lot to type when you have to write it 20 times or something....

cheers!
Three answers:
markum
2010-03-11 22:04:46 UTC
The key is to pick names that other people can easily understand, and you can understand after a few weeks of not looking at the code.



All three of these equations are functionally the same, but which of these makes the most sense?

1) a0=a1*a2

2) d=r*t

3) distance=rate*time



Some people like conventions like Hungarian notation and CamelCase. Some commonly accepted conventions are given at http://en.wikipedia.org/wiki/Identifier_naming_convention
modulo_function
2010-03-11 21:57:27 UTC
Your tutor sounds a little pedantic. Your name should be suggestive. There are strong conventions for naming classes, objects, methods, etc. For temp variables you want a short name. I tend the either place the word temp at the beginning or end. Thus if distance is the variable then I might use distTemp for the temporary version.
2010-03-11 21:51:38 UTC
yes and no, it mostly depends on the language and then there are different guidelines and schools of thought on how to do it. I'd just follow what your instructor says


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...