CppCoreGuidelines
CppCoreGuidelines copied to clipboard
Using f as function name and internal variables invites confusion. Recommending using better name for functions.
Hello everyone,
I was reading R12 and observed that the function name f is shadowed by the file variable inside the function. Then, f is used to call the finally block.
void f(const string& name)
{
FILE* f = fopen(name, "r"); // open the file
vector<char> buf(1024);
auto _ = finally([f] { fclose(f); }); // remember to close the file
// ...
}
This is potentially very confusing to the general reader who might not know about lambda scope captures.
"Does finally use the variable or the function f?" would be their question.
R13 uses fun for the function name. Using func might be better, but fun is still good, and much easier to understand than f.
Recommending using fun at least for the function name used in R12.
Thanks :)
If you want you can create a pull request with exactly that change.
Editors call: Sure, let's change f(...) to func(...). Thanks!