Suppose I have a Utility class in a utility.h file:
class Utility { public: static double longDescriptiveName(double x) { return x + 42; } };
And then I found that I was using the longDescriptiveName(...) LOT function. So, as the irresponsible C ++ programmer that I am when I had too much coffee, I create a new utilitymacros.h file and add the following to it:
#define ldn Utility::longDescriptiveName
Now I include "utilitymacros.h" in any *.cpp where I use ldn(...) , and my heart is filled with joy over how much more convenient it is to use type 3 letters versus 28.
Question: Is there a safer (more correct) way to do this than with #define ?
I noticed that I need to enable "utilitymacros.h" after including the forwards headers, which I clearly don't like, because it is a sign of collisions (although the Boost errors that I get are not very clear regarding what the collision is).
Clarification 1: Reading the code
If you can say that this affects the readability of the code, I assure you that this is not so, because it is a small set of functions that are used by A LOT. An example that is widely known is stoi for stringToInteger . Another is pdf for probabilityDensityFunction etc. Therefore, if I want to do the following, stoi more readable, in my opinion:
int x = stoi(a) + stoi(b) + stoi(c) + stoi(d);
than:
int x = Utility::stringToInteger(a) + Utility::stringToInteger(b) + Utility::stringToInteger(c) + Utility::stringToInteger(d);
Or:
int x = Utility::stringToInteger(a); x += Utility::stringToInteger(b); x += Utility::stringToInteger(c); x += Utility::stringToInteger(d);
Clarification 2: Macro Editor
I use Emacs as my IDE to select Kinesis keyboards, so you KNOW I use a ton of keyboard macros, custom keyboard shortcuts, and actually change what I see in the editor and what is actually stored in h / cpp file. But nevertheless, I feel that the simplicity and visual readability (as stated above) of using the abbreviations of the function in several separate cases are indeed the result I'm looking for (this, of course, depends on the degree).