Beyond 2.8 - some design thoughts

John Ralls jralls at ceridwen.us
Mon Dec 25 14:20:49 EST 2017



> On Dec 25, 2017, at 9:24 AM, Geert Janssens <geert.gnucash at kobaltwit.be> wrote:
> 
> Op maandag 25 december 2017 17:34:22 CET schreef Christian Stimming:
>> As for the namespace aliases such as "namespace gia =
>> gnc::import::aqbanking", those must not appear in header files, but may
>> appear in cpp files. However, I didn't like those in general, as it makes
>> readability for other people much harder. In terms of mutual readability of
>> code, I would rather stick to the plain namespace names and that's it.
>> 
> Ok. I know we are using them in our new c++ code when referencing certain 
> boost namespaces. And the readability aspect works both ways. If namespaces 
> get too long, the code becomes hard to read as well. I have found my IDE 
> (kdevelop currently) quite helpful in deciphering the aliases. I'm not sure 
> which way I like best currently.

I used them in GncDateTime because the boost::date_time developer got carried away in exactly the way I warned against. Those aliases are in a single implementation file that’s intended to hide the implementation details from the rest of GnuCash.

There’s another use of aliases that does belong in headers: Declaring a pseudo-type for container classes. For example, from gnc-backend-sql.hpp:

using VersionPair = std::pair<const std::string, unsigned int>;
using VersionVec = std::vector<VersionPair>;

helps express the container’s intended use (a vector of version tags) and is much more readable in code than writing std::vector<std::pair<const std::string, unsigned int>>> all over the place.

Regards,
John Ralls


More information about the gnucash-devel mailing list