|
Choosing sensible and descriptive names is an important part of the documentation of a program. Well chosen names greatly enhance the readability of a program. Poorly chosen names lead to confusion.
If a function compares two strings, a reasonable name for it is compareStrings. If a function reads a graph, call it readGraph.
If a variable is your dog's name, you might call it myDogsName. You can feel free to use short names such as x and y for parameters and variables that only exist in a small function.
But watch out. Suppose you describe a one-way road by two parameters, where the road starts and where it ends. If you call those two parameters u and v, it is easy for you to confuse the two, and that is just asking for more mistakes and more debugging. If you call them roadStart and roadEnd, you will avoid those mistakes.
Here are few misleading function names that past students have used in their programming assignment submissions. (Yes, I read your submissions.)
|
The standards require you to choose sensible function names. Most importantly, do not choose function names that are misleading about what the function does.
|