-
Notifications
You must be signed in to change notification settings - Fork 68
Description
Up until now we've been trying to keep the number of source files low because of concerns over C++'s inefficient handling of multiple units of compilation, specifically when hierarchies of included header files are involved. It's become clear that this isn't worth the trade-off anymore, because the arbitrary grouping of functionality into preexisting files has made the codebase difficult to navigate.
Apart from redistributing logic across more source files, we'll also take this opportunity to reduce the use of the suffix "Manager" in the various namespace identifiers, as it's something of an anti-pattern because it adds very little meaning yet makes them more difficult to read and write. We don't necessarily need to remove its use from all existing namespaces, but we should avoid using it in new ones. It should be removed from some existing namespaces, though.
Another thing we should do is cleanly separate internal and external functions and data, instead of exporting everything in the corresponding header file.
For example, MissionManager::endTask() is currently defined in MissionManager.cpp and declared in the MissionManager namespace in MissionManager.hpp.
In MissionManager.hpp:
namespace MissionManager {
// ...
bool endTask(CNSocket *sock, int32_t taskNum, int choice=0);
// ...
}In MissionManager.cpp:
bool MissionManager::endTask(CNSocket *sock, int32_t taskNum, int choice) {
// ...
}The proper way to go about it is to not put the function in a namespace at all, and to instead both define and declare it with the static keyword, and the declaration should be put near the top of the source file, after the global variables but before the function definitions, instead of in the header file. Like so:
static bool endTask(CNSocket *sock, int32_t taskNum, int choice=0);
// other function definitions...
static bool endTask(CNSocket *sock, int32_t taskNum, int choice) {
// ...
}Internal global variables should have static in their definition near the top of the source file and shouldn't be declared anywhere else.