3 ms·
> Variable name length should be proportional to its scope. I remember the rule from CC, and I kinda like it. But there are obvious exceptions to that. There a
by js8 7y ago
> Variable name length should be proportional to its scope.
I remember the rule from CC, and I kinda like it. But there are obvious exceptions to that. There are things like logging or printing in the global scope that one would die for to have short names.
Also if you have an object with many fields that you need to access. Then it is more convenient to give it a short name, to make the code more readable.
So parent's suggestion, to have length of the name inversely proportional to its frequency, is also a good point. The two conventions unfortunately sometimes contradict.
- croo 7y agoI agree and these are definetly just guides not hard rules to follow. What I'm really against is using a short name which don't convey any meaning. For example 'getRtw' - which is a great shorthand for something we may never know until we go and find out. That is unacceptable naming anywhere regardless of scope, function, whatever. Use short but meaningful, pronouncable words as names and don't left out random characters from it (like usr instead of user) because thats just silly.