In my current code project, there is an awful lot of constant strings I use to print out error messages.
Hardcoding such strings is generally considered to be bad practice. Now I'm searching for a "clean way" to include these strings in my program. Therefore I've written a "constants.h" and "constants.cpp" which looks something like
#ifndef CONSTANTS_H_ #define CONSTANTS_H_ extern std::string error_message_1; #endif
and the constants.cpp:
#include "constants.h" std::string error_message_1 = "this is just a sample, not my actual naming convention. move on the the question ;-)"
So you might see the problem I have with this: due to a lot of error messages, the variable name itself is fairly long. The error message is even longer, so it crashes the standard 80 characters in one line of code.
Obviously I want my code nice and clean. I don't like going far beyond the 80 charactes per line of code. I don't like somthing like the following either:
std::string error_message_1 = "this is just a sample about how to" " have one string across many lines" " in the source code. this is not " "very pretty too.."; std::string msg = "and suddenly there's one line which is good.."; std::string error_message_with_longer_name = "and it's even " "uglier with not " "equally long " "variable names";
Storing the strings in an external file which one would read in at the start of the program does not seem to be optimal too since the compiler cannot warn about missing strings. Basically this would be a mess to maintain.
So what do you do about it? Is there such a nice thing as "Resources", which I know of Android (or is it Java in general?) development?
Note: Please do NOT tell me that my naming convention is bad. The above is just an example. It's not what it looks like ;-)