Namespaces, file names,...

Geert Janssens janssens-geert at telenet.be
Fri Sep 5 05:46:23 EDT 2014


This topic was lightly touched in the doxygen/design thread currently active on this list. I 
thought it to be important enough to start a new thread on it.

Historically, gnucash as acquired a lot of namespaces (think function and type prefixes) for 
various reasons.

Some examples:
* The oldest engine code uses xaccXYZ because gnucash started as a continuation of the xacc 
project (xacc for X Accounting by the way).
* More recent engine code and most of the gui related code usually use gnc_ copying the gtk 
name space standards.
* The qof library introduced qof_ because it was meant to become a separate library at one 
point in time.

Types are different still:
* The oldest engine code doesn't use prefixes at all ("Split", "Transaction",...)
* More recent engine code uses Gnc or GNC, gui code is mostly into Gnc as well.

And so on...


The problem with this is that it makes the gnucash "framework" hard to learn. It's not possible 
to learn by similarity like it is in strongly namespaced frameworks such as gtk, qt or boost. 
Those frameworks have a logic to their name structure, so if you know one part of the 
framework you can already imagine what other functions and types in the framework will be 
called. That speeds up adoption a lot.

The same goes for file names, and especially header files. If there is a recognizable logic in the 
names of the header files, that makes it much faster to learn how to use the framework.

Now since one of our current design goals is to port our engine code to C++, that means we will 
more or less rewrite every single function and type in it. That would IMO be a good time to think 
about how we want to structure the new classes name-wise and come to a more coherent set 
of names.

I have seen how some frameworks do it and clearly there are different ways. I don't know 
however whether there exist formal theories or guidelines that we could use to formulate our 
own naming rules.

For example, in recent years I have worked mostly with the GLib/Gtk frameworks. Some of their 
naming rules include
* Object names are prefixed with G (for GLib) and Gtk (for Gtk). The names are camel-cased.
* Function names are prefixed with g_ (for GLib) and gtk_ (for Gtk). An the names use _ to 
separate words.

If we had planned to continue to use GLib/Gtk in the long term, I would have proposed to use a 
similar naming scheme, using our own Gnc/gnc_ prefixes. That would allow newcomers to 
leverage the muscle memory built up on GLib and Gtk naming.

The plan is however to move away from those in favour of C++ based alternatives, so I think it 
would make more sense to look for examples of namespacing in the C++ world. That world is 
unknown to me unfortunately so...

Suggestions anyone ?

Geert


More information about the gnucash-devel mailing list