Every time I have some functionality which is in the direction of "utility", I end up wondering which option is the best. For instance, printing message structs (own or external), some encoding/decoding code or simply a few useful conversion functions in the context I'm working.
The options I think about are:
1) Static function in helper class/struct.
struct helper
{
static bool doSomething(...);
};
2) Nonmember function.
namespace helper
{
bool doSomething(...);
}
3) Static nonmember function.
namespace helper
{
static bool doSomething(...);
}
In some cases there might be necessary to initialize or keep state in the "utility", so then I go for option 1 to avoid "global" state. However, if there is no state that needs to be kept, should I then option 2 or 3? What's the practical difference between option 2 and 3?
What is important to consider and is there a preferred way to approach this? Thanks!