Namespaces, file names,...
jralls at ceridwen.us
Wed Sep 10 09:48:10 EDT 2014
On Sep 10, 2014, at 4:51 AM, Christian Stimming <christian at cstimming.de> wrote:
> Zitat von Derek Atkins <warlord at mit.edu>:
>> I agree that we don't need to have a directory for the namespace, and I
>> also don't think we need to have namespaces for each "module/library".
>> E.g., I don't think we need GnuCash::Engine::Account. I suspect doing
>> so would just add complexity where it might not be warranted.
> I don't want to vote for extra namespaces, but I'd like to point out one technical reason for someone's preferences here: If the preferred tool of coding is something cmdline-based or emacs, chances are that extra directories mean extra typing work and are rather avoided. If the tool of coding is an IDE such as eclipse, qtcreator, or Visual Studio, the directories play only a minor role anymore (if visible at all in the project view) and chances are that they get to be used more often, for grouping of similar things and such. And in C++ (just as in java), adding extra namespaces for extra directories can be seen as the mapping between the file system and the compiler. In such a context, one wants to use gnc::engine::Account, knowing that it resides in the header file <gnc/engine/Account.h> on the disk, or gnc::backend::xml::XmlFile, knowing that it resides in <gnc/backend/xml/XmlFile.h>. You can always get rid of the namespace qualifications by using (no pun intended) "using namespace", but I know from my own learning curve that multiple namespaces seem rather smelly when coming from a C background. After years of C++ I got to like them, especially if they are implemented as a direct mapping from the directory structure on disk to the class structure in the namespaces. But that's just my personal take on this.
That practice of Java is an abomination, and the compiler doesn't need namespaces to map the file system for it. I think you mean build-system anyway: The compiler works on one compilation unit at a time, which consists of the input file plus its includes.
Namespaces exist to isolate identifier names so that they can be reused. The only reason to divide up the GnuCash namespace would be if you envision needing to use the same class name or free-function name in two different contexts. Otherwise it just adds verbosity.
More information about the gnucash-devel