If a class method doesn't rely on the class' state then it can be static. Is it good or bad practice to make such methods static where this is the case?
(Tagged as C# but probably applies to many OO languages where methods must be class members.)
If a class method doesn't rely on the class' state then it can be static. Is it good or bad practice to make such methods static where this is the case?
(Tagged as C# but probably applies to many OO languages where methods must be class members.)
Is it good or bad practice to make such methods static where this is the case?
Honestly, there is no way to say if 100% this is good or bad practice. A number of people follow the general rule that if it can be made static then do so. It shows that there isn't a requirement on state, and technically (at least in C#) it is a little faster.
That being said, it all depends on the composition of the code around the methods, and how the application is going to evolve.
Visual Studio Code Analysis and ReSharper suggest to make those methods static, because there is a tiny performance advantage:
From documentation:
For non "performance-sensitive" code this is a matter of taste. I personally obey to ReSharper's suggestions if I have no good reason to not do so.