Re:How C++ Resolves a Function Call
by einpoklum on Tuesday March 16, 2021 @02:43PM
(#26481047)
Rule of thumb: If your code has ambiguities that make you reach for the details of name resolution rules, or depend on some finer point within them, then - seriously consider differentiating the names.
In the example in the article - I would go to some trouble to avoid having both:
either blasting asteroids happens in the context of galaxies, or it doesn't. If there are _different kinds_ of blasting of asteroids - very well, make that explicit.
Also,
bool blast(Target target);
would be somewhat confusing, since people may expect `blast()` to not return anything and will neglect to check the returned value. And wouldn't it make more sense to just have a default amount of force for the blast? ... again, if it's a different kind of blast, don't name both functions the same.
PS:
* "Better is a good name than fine oil" (that's a biblical proverb).
* Don't be a smart-ass when naming! You'll smile for a second, others will cry for years.
* Don't be stingy with a few more characters in your name - we can handle it.
In the example in the article - I would go to some trouble to avoid having both:
andtemplate <typename T> void blast(T* obj, float force);
either blasting asteroids happens in the context of galaxies, or it doesn't. If there are _different kinds_ of blasting of asteroids - very well, make that explicit.
Also,
bool blast(Target target);
would be somewhat confusing, since people may expect `blast()` to not return anything and will neglect to check the returned value. And wouldn't it make more sense to just have a default amount of force for the blast? ... again, if it's a different kind of blast, don't name both functions the same.
PS:
* "Better is a good name than fine oil" (that's a biblical proverb). * Don't be a smart-ass when naming! You'll smile for a second, others will cry for years. * Don't be stingy with a few more characters in your name - we can handle it.