r/csharp • u/Zardotab • Feb 24 '21
Discussion Why "static"?
I'm puzzled about the philosophical value of the "static" keyword? Being static seems limiting and forcing an unnecessary dichotomy. It seems one should be able to call any method of any class without having to first instantiate an object, for example, as long as it doesn't reference any class-level variables.
Are there better or alternative ways to achieve whatever it is that static was intended to achieve? I'm not trying to trash C# here, but rather trying to understand why it is the way it is by poking and prodding the tradeoffs.
0
Upvotes
View all comments
Show parent comment
1
u/Zardotab Feb 25 '21 edited Feb 26 '21
Singletons would be a lot more code. See the FormValidation scenario for a use-case to experiment with. [Edited]
Not just that, but shorter code is often easier to read and introduces less bugs: less things to type wrong (keyboard-wise). We don't want instantiation to "hang around" just to make OOP happy. Ideally we want it when it serves a purpose and want to skip when it doesn't.