3 ms·
The naming problem can not be separated from semantics and programming style. For example, I use the principle "name a function so that ideally there's no need
by mojuba 6y ago
The naming problem can not be separated from semantics and programming style. For example, I use the principle "name a function so that ideally there's no need to document it or check its source", i.e. function names should be descriptive enough but that implies that functions should be small, do one thing and do it well.
Another principle I use is: if a variable's definition and usage can fit on the screen then give it the shortest possible name. Again, this implies that both functional-leaning style of programming and short naming are encouraged.
Corollary: there's no reason to give an int loop variable any name other than "i" unless there's a naming conflict or the loop body is too long (which it shouldn't be). Right?
But at the end of the day I'd formulate the fundamental principle of naming as:
Do whatever it takes to reduce mental tax for the reader, assuming the reader is aware of the context of the codebase, and roughly has a median level of experience in programming.
The latter part is important because I think good code should teach less experienced programmers rather than make it easier for them to read it at the expense of succinctness.