#Static class or not?
31 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
Static class or not?
I would advise against this
Well, to be more precise, I would advise against this **if non-constant static member variables are involved **
because then you'd be introducing mutable global state in your program and that's the breeding ground for headache-inducing problems, all sorts of them
if you only have static member functions which don't rely on any non-constant static member variables, then I'd consider turning the class into a namespace, because those are all essentially free functions
@cobalt locust he is right
Just clarifying 2 things:
- You would advice against turning a class into a static one?
- Non-constant static member variables from other classes?
I advise against making code rely on mutable global state, wherever that state is located
<pedantic>there's also no such thing as a static class, this is a C# concept iirc, static in C++ can mean different things based on context but it never applies to classes</pedantic>
it's fine to use static members
but if you're turning every member function from a class into static ones, then drop the class altogether and make it a namespace
I mean that in that class only static methods will be used
and there will be (probably) no const variables
I understood, but terminology is only going to get more important as you go, hence the remark 😛
it's fine to rely on const variables
it's the non-const ones that are a problem if you need to store them outside the functions
my bad if I caused misunderstandings
no worries 
that is because they effectively become global state that your functions are relying on
what happens if two functions that rely on those are called at the same time ?
if the global variables they access are non-const, they might be tempted to write to it, both at the same time, or one while the other is reading from it
that's a race condition and it makes things go boom
if they're const you have no such problem
but then again you should turn that class into a namespace
if you're in this predicament, thankfully the solution isn't to write code that gracefully handles race conditions (that would be needlessly complex): instead, just don't make the member functions static 
if @cobalt locust your question is solved then make it !solved