Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. code smell ? C# public class with everything in it declared 'static

code smell ? C# public class with everything in it declared 'static

Scheduled Pinned Locked Moved C#
csharpvisual-studioquestiondiscussion
4 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BillWoodruff
    wrote on last edited by
    #1

    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

    OriginalGriffO E 2 Replies Last reply
    0
    • B BillWoodruff

      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

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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 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

      L 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        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!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • B BillWoodruff

          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

          E Offline
          E Offline
          englebart
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups