code smell ? C# public class with everything in it declared 'static
-
i advised an article writer (newbie), here, that his use of the above syntax is not a good programming practice. my thought is why would you have a potentially 'newable class (since it gets a default constructor) where calling 'new meant a "useless" instance. thinking that over ... given VS and ReSharper don't flag that ,,, i lean towards thinking maybe during development: who cares, as long as it compiles; you might want to add 'public stuff later, but, for production code, that is a code smell. i have never used that syntax, and never put a static class in a public class, either. your thoughts ?
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
-
i advised an article writer (newbie), here, that his use of the above syntax is not a good programming practice. my thought is why would you have a potentially 'newable class (since it gets a default constructor) where calling 'new meant a "useless" instance. thinking that over ... given VS and ReSharper don't flag that ,,, i lean towards thinking maybe during development: who cares, as long as it compiles; you might want to add 'public stuff later, but, for production code, that is a code smell. i have never used that syntax, and never put a static class in a public class, either. your thoughts ?
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
My feeling is that overuse of static generally means they don't understand OOPs properly - it's often a "it worked in C" approach to an app rather than using objects to avoid unnecessary globals (both methods and variables) If he's a coding newbie, it's likely that his tutor grew up in a procedural environment and has just learned the syntax of an OOPs language rather the principles behind it.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
My feeling is that overuse of static generally means they don't understand OOPs properly - it's often a "it worked in C" approach to an app rather than using objects to avoid unnecessary globals (both methods and variables) If he's a coding newbie, it's likely that his tutor grew up in a procedural environment and has just learned the syntax of an OOPs language rather the principles behind it.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
I don't see the point of creating a singleton when there is a class that will never be a component of anything else. My apps usually have some sort of "data repository" in memory that needs to be accessed from all over the app; a static class is supremely convenient in this case. "Static" doesn't define the data; it only defines the "references". They could all be observable collections with different subscribers. Dependency injection in this case is obsessing (IMO).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
i advised an article writer (newbie), here, that his use of the above syntax is not a good programming practice. my thought is why would you have a potentially 'newable class (since it gets a default constructor) where calling 'new meant a "useless" instance. thinking that over ... given VS and ReSharper don't flag that ,,, i lean towards thinking maybe during development: who cares, as long as it compiles; you might want to add 'public stuff later, but, for production code, that is a code smell. i have never used that syntax, and never put a static class in a public class, either. your thoughts ?
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
If it makes sense as a “bundle” of statics, then make the constructor private. If it is more class-like, then a singleton would make it easier to substitute a different implementation later. I agree with you that it should be last resort and usually a code smell.