Contents
Is it bad to have long variable names?
Having really long variable names will muddle up your code’s readability, so you want to avoid those. But on the other end of the spectrum, you want to avoid ultra-short names or acronyms like “n” or “ne.” Short, cryptic names like these will cause someone trying to read your code to tear their hair out.
Can variable names be arbitrarily long?
Variable names can be arbitrarily long. They can contain both letters and numbers, but they have to begin with a letter. Although it is legal to use uppercase letters, by convention we don’t. If you do, remember that case matters.
Do longer variable names take up more memory?
It forgets about each line when it moves on to the next, so it has no way to track variables except by their names in the source. Since the full source code had to be kept in memory at run time, and it was often limited to 64 kB or less, variable names really did matter!
Which is not legal variable name?
The following are examples of invalid variable names: age_ (ends with an underscore); 0st (starts with a digit); food+nonfood (contains character “+” which is not permitted)
How do you write a good variable name?
A good variable name should:
- Be clear and concise.
- Be written in English.
- Not contain special characters.
- Not conflict with any Python keywords, such as for , True , False , and , if , or else .
Is it OK to have long variable names?
Having really long variable names will muddle up your code’s readability, so you want to avoid those. But on the other end of the spectrum, you want to avoid ultra-short names or acronyms like “n” or “ne.”. Short, cryptic names like these will cause someone trying to read your code to tear their hair out.
What’s the best way to choose variable names?
Choosing variable names is more art than science. You want something that doesn’t take an epoch to type, but long enough to be expressive. It’s a subjective balance. Ask yourself, if someone were looking at the variable name for the first time, is it reasonably likely that person will understand its purpose?
How long should variable names be in Fortran?
On the first point, while languages like Fortran did limit the length of variable names (to 6 characters), modern programming languages have no restrictions so don’t feel forced to use contrived abbreviations. Don’t use overly long variable names either, but if you have to favor one side, aim for readability.
What to put at the end of a variable name?
First, decide on common abbreviations: avg for average, max for maximum, std for standard deviation and so on. Make sure all team members agree and write these down. Put the abbreviation at the end of the name. This puts the most relevant information]