After reading through the question and the answers I came to the conclusion that this is were comments can come into play. I had recently read this Q/A Guessing a number, but comments concerning and the accepted answer gave me insight to the situation here. Use comments to explain the why, let the code explain the how. I can use your function similarly for each case as an example:
bool SomeClass::saveData() {
std::ofstream saveFile(m_filename);
if (!saveFile.is_open())
return false;
saveFile << m_member1 << std::endl; // I would replace `endl` with `'\n'`
saveFile << m_member2 << std::endl; // for performance reasons.
// I intentionally want to close the file before the closing scope to
// free up limited resources and to log potential exceptions and errors.
saveFile.close();
return true;
}
bool SomeClass::saveData() {
std::ofstream saveFile(m_filename);
if (!saveFile.is_open())
return false;
saveFile << m_member1 << std::endl; // I would replace `endl` with `'\n'`
saveFile << m_member2 << std::endl; // for performance reasons.
// Resources and errors are not a concern: relying on RAII no need
// to call file.close();
return true;
}
Then with the appropriate type of commenting for the appropriatevalid reasons, might serve you well. Then at least this way; one would know that you intended to call or omit it and why! Well written code is the how and shouldn't need comments.