Lets say I need to write several functions processing some data. These functions are performing a single task – some mathematical calculations. I suppose there is no need to combine them with some data members.
Shall I use:
- a class without data members and declare these functions as static methods so I can use them without creating class object,
- or an anonymous namespace,
- or maybe I need something more complicated in terms of architecture and design?
Actually, the language I am writing in is C++, but I think this question doesn’t depend on what the language of development is.
I don’t see why you would put them in an anonymous namespace. It is done to make sure these functions are only used in one compilation unit, which has nothing to do with your question.
Now, to choose between static functions in a class or free functions in a utility namespace, it’s up to your needs. There is a few differences between these solutions: