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. .NET (Core and Framework)
  4. Stylecop burst my bubble

Stylecop burst my bubble

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpvisual-studioquestion
7 Posts 6 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.
  • H Offline
    H Offline
    hammerstein05
    wrote on last edited by
    #1

    So, I decided that I would download Stylecop and see what sort of issues it took with my code. I found a couple of things surprising, one frustrating. My frustration was that I'm not allowed to pad with spaces? For a long time now, I've enjoyed setting up Visual Studio to add spaces in empty parentheses, spaces in method calls etc. I've just found the code to be all the more readable. But, following Stylecop rules, I've got no extra room. I mean, this will please the people I work with, they don't like the spaces but I've come to like it. if ( value < maximumValue ) { } I've found to be more readable than; if(value < maximumValue) { } My next surprise was that it was telling me to put my using statements inside my namespace. I've not seen this done before in code samples I've seen even from MS,and considering this tool comes out of Microsoft it took me by surprise. Can anybody explain this one to me? I understand the idea of Stylecop and I'm willing to follow most. Is there a way of editing the rules?

    D E S 3 Replies Last reply
    0
    • H hammerstein05

      So, I decided that I would download Stylecop and see what sort of issues it took with my code. I found a couple of things surprising, one frustrating. My frustration was that I'm not allowed to pad with spaces? For a long time now, I've enjoyed setting up Visual Studio to add spaces in empty parentheses, spaces in method calls etc. I've just found the code to be all the more readable. But, following Stylecop rules, I've got no extra room. I mean, this will please the people I work with, they don't like the spaces but I've come to like it. if ( value < maximumValue ) { } I've found to be more readable than; if(value < maximumValue) { } My next surprise was that it was telling me to put my using statements inside my namespace. I've not seen this done before in code samples I've seen even from MS,and considering this tool comes out of Microsoft it took me by surprise. Can anybody explain this one to me? I understand the idea of Stylecop and I'm willing to follow most. Is there a way of editing the rules?

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      I've never used it but a few comments on what you've found.

      hammerstein05 wrote:

      pad with spaces

      Screen space is a highly prized resource IMO. Extra spaces (horizontal especially as vertical can be conrtolled with collapsing sections/regions etc) drive me nuts when working on a laptop or smaller than ideal display.

      hammerstein05 wrote:

      using statements inside my namespace

      I never do this, but it makes sense as the usings only apply to objects inside that namespace.

      Dave

      If this helped, please vote & accept answer!

      Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      M 1 Reply Last reply
      0
      • H hammerstein05

        So, I decided that I would download Stylecop and see what sort of issues it took with my code. I found a couple of things surprising, one frustrating. My frustration was that I'm not allowed to pad with spaces? For a long time now, I've enjoyed setting up Visual Studio to add spaces in empty parentheses, spaces in method calls etc. I've just found the code to be all the more readable. But, following Stylecop rules, I've got no extra room. I mean, this will please the people I work with, they don't like the spaces but I've come to like it. if ( value < maximumValue ) { } I've found to be more readable than; if(value < maximumValue) { } My next surprise was that it was telling me to put my using statements inside my namespace. I've not seen this done before in code samples I've seen even from MS,and considering this tool comes out of Microsoft it took me by surprise. Can anybody explain this one to me? I understand the idea of Stylecop and I'm willing to follow most. Is there a way of editing the rules?

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        You can turn off some of Style Cops annoyances. Besides, you should be spending more time focusing on the logic and functionality of your code than the style. In fact, one of the first things I do in a contract that involves code reviews is insert an obvious error into my code for review. If this first comment about my code is style related I know that most people in the room are not playing for the right team. It is about code first.

        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

        1 Reply Last reply
        0
        • D DaveyM69

          I've never used it but a few comments on what you've found.

          hammerstein05 wrote:

          pad with spaces

          Screen space is a highly prized resource IMO. Extra spaces (horizontal especially as vertical can be conrtolled with collapsing sections/regions etc) drive me nuts when working on a laptop or smaller than ideal display.

          hammerstein05 wrote:

          using statements inside my namespace

          I never do this, but it makes sense as the usings only apply to objects inside that namespace.

          Dave

          If this helped, please vote & accept answer!

          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          M Offline
          M Offline
          Mike Poz
          wrote on last edited by
          #4

          DaveyM69 wrote:

          hammerstein05 wrote: using statements inside my namespace I never do this, but it makes sense as the usings only apply to objects inside that namespace.

          I asked the StyleCop folks about this and that was their answer, to limit the using statements to apply only to the objects inside the namespace. Their assumption is that you would only have one namespace per file, so I assume that there would also be a stylecop warning for multiple namespaces in a single file. Never tried it to validate this assumption though.

          Mike Poz

          C 1 Reply Last reply
          0
          • M Mike Poz

            DaveyM69 wrote:

            hammerstein05 wrote: using statements inside my namespace I never do this, but it makes sense as the usings only apply to objects inside that namespace.

            I asked the StyleCop folks about this and that was their answer, to limit the using statements to apply only to the objects inside the namespace. Their assumption is that you would only have one namespace per file, so I assume that there would also be a stylecop warning for multiple namespaces in a single file. Never tried it to validate this assumption though.

            Mike Poz

            C Offline
            C Offline
            Chris Trelawny Ross
            wrote on last edited by
            #5

            Not questioning you, but the StyleCop folks: if they're assuming that you'll only have one namespace in a file, what does it matter if the usings are inside or outside the namespace?

            S 1 Reply Last reply
            0
            • C Chris Trelawny Ross

              Not questioning you, but the StyleCop folks: if they're assuming that you'll only have one namespace in a file, what does it matter if the usings are inside or outside the namespace?

              S Offline
              S Offline
              Scott Dorman
              wrote on last edited by
              #6

              Take a look at the document here[^]. In a nutshell: There are subtle differences between placing using directives within a namespace element, rather than outside of the namespace, including: 1. Placing using-alias directives within the namespace eliminates compiler confusion between conflicting types. 2. When multiple namespaces are defined within a single file, placing using directives within the namespace elements scopes references and aliases.

              Scott Dorman

              Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


              Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

              1 Reply Last reply
              0
              • H hammerstein05

                So, I decided that I would download Stylecop and see what sort of issues it took with my code. I found a couple of things surprising, one frustrating. My frustration was that I'm not allowed to pad with spaces? For a long time now, I've enjoyed setting up Visual Studio to add spaces in empty parentheses, spaces in method calls etc. I've just found the code to be all the more readable. But, following Stylecop rules, I've got no extra room. I mean, this will please the people I work with, they don't like the spaces but I've come to like it. if ( value < maximumValue ) { } I've found to be more readable than; if(value < maximumValue) { } My next surprise was that it was telling me to put my using statements inside my namespace. I've not seen this done before in code samples I've seen even from MS,and considering this tool comes out of Microsoft it took me by surprise. Can anybody explain this one to me? I understand the idea of Stylecop and I'm willing to follow most. Is there a way of editing the rules?

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #7

                You can selectively enable/disable most of the rules but there isn't a way to edit a rule. Putting using statements inside the namespace is recommended for the following reasons:

                From http://www.thewayithink.co.uk/stylecop/sa1200.htm[^] There are subtle differences between placing using directives within a namespace element, rather than outside of the namespace, including: 1. Placing using-alias directives within the namespace eliminates compiler confusion between conflicting types. 2. When multiple namespaces are defined within a single file, placing using directives within the namespace elements scopes references and aliases.

                The spacing reccomendations are most likely due to screen space concerns. Anyway, the code you show would look like this to meet the StyleCop settings:

                if (value < maximumValue)
                {
                }

                Scott Dorman

                Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


                Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

                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