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. The Lounge
  3. StyleCop - Aarrgh

StyleCop - Aarrgh

Scheduled Pinned Locked Moved The Lounge
questioncsharpcssvisual-studiocom
25 Posts 14 Posters 0 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.
  • P Pete OHanlon

    The Man from U.N.C.L.E. wrote:

    That last one is the worst. The reasoning is that you can put more than one namespace in the same file so using statements should be scoped to the namespace not the file. Sorry, but in that instance I would want to scope them to the file as well! Also, putting two namespaces in the same file will fail another stylecop rule thereby making this one redundant.

    Wow. If I remember rightly, they also have a rule about specifying only one class per file.

    I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

    Forgive your enemies - it messes with their heads

    My blog | My articles | MoXAML PowerToys | Onyx

    N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #16

    Pete O'Hanlon wrote:

    Wow. If I remember rightly, they also have a rule about specifying only one class per file.

    Which is a good rule to follow in my opinion. I even use that for enums, even small ones.

    Regards, Nish


    My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)

    L P 2 Replies Last reply
    0
    • P peterchen

      The Man from U.N.C.L.E. wrote:

      Use spaces not tabs (why? tabs are neater)

      because tabs break this:

      switch (foo)
      {
      case Bar: RunBar(); break;
      case Foobar: RunFoo(); RunBar(); break;
      }

      The Man from U.N.C.L.E. wrote:

      Put a space before and open bracket, or place the bracket on a new line (why? it makes my code look neater without the space for if statements etc. takes up less lines as well.)

      Because most coders, when growing up, migrate away from compactness and towards expressive structure.

      The Man from U.N.C.L.E. wrote:

      Put using statements inside of namespaces not outside.

      Umm.... hrrrrr...... errr... You know that you can disable individual rules, don't you?

      Agh! Reality! My Archnemesis![^]
      | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

      T Offline
      T Offline
      The Man from U N C L E
      wrote on last edited by
      #17

      I know, I can disable rules but that rather defeats the point. I started from the point of how can I be expected to match the rules if the Visual Studio generated code itself does not. As to coding and brackets, I prefer, the following, though I know personal preference and all that.

      switch (foo){
      case Bar:
      RunBar();
      break;
      case Foobar:
      RunFoo();
      RunBar();
      break;
      }

      In this example Style cop would prefer the following:

      switch (foo)
      {
      case Bar:
      RunBar();
      break;
      case Foobar:
      RunFoo();
      RunBar();
      break;
      }

      Who can really say which is more readable, though I would use spaces if pasting on CP because it is easier to type in the editor, that does not allow you to type tabs.

      If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

      P 1 Reply Last reply
      0
      • N Nish Nishant

        Pete O'Hanlon wrote:

        Wow. If I remember rightly, they also have a rule about specifying only one class per file.

        Which is a good rule to follow in my opinion. I even use that for enums, even small ones.

        Regards, Nish


        My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)

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

        Nishant Sivakumar wrote:

        Which is a good rule to follow in my opinion. I even use that for enums, even small ones.

        Same here. Makes life easier 2 or 3 years down the road. Cheers, Drew.

        1 Reply Last reply
        0
        • N Nish Nishant

          Vikram A Punathambekar wrote:

          Can you not suppress rules? FxCop allows you to do that.

          Yes you can. It even lets you specify new rules. It baffles me that people would download a free customizable app, refuse to customize it, and then complain about its default behavior in a public forum using their real name. :~

          Regards, Nish


          My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)

          T Offline
          T Offline
          The Man from U N C L E
          wrote on last edited by
          #19

          Got some interesting responses out of it though. MS does have some good explanations of the reasoning behind each rule, and clearly you have to chose the set for you as some rules don't sit well together. Customising the rules was the second thing I did. It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

          N P 2 Replies Last reply
          0
          • T The Man from U N C L E

            Got some interesting responses out of it though. MS does have some good explanations of the reasoning behind each rule, and clearly you have to chose the set for you as some rules don't sit well together. Customising the rules was the second thing I did. It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.

            If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #20

            The Man from U.N.C.L.E. wrote:

            It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.

            Yeah I hear you there. The VS team seems to have been wholly unaware of the StyleCop guidelines :-) BTW, my real name jab was an attempted joke (since you are not using your real name at all)!

            Regards, Nish


            My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)

            T 1 Reply Last reply
            0
            • N Nish Nishant

              Pete O'Hanlon wrote:

              Wow. If I remember rightly, they also have a rule about specifying only one class per file.

              Which is a good rule to follow in my opinion. I even use that for enums, even small ones.

              Regards, Nish


              My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #21

              I follow that rule - and it clarifies why using statements are per namespace.

              I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

              Forgive your enemies - it messes with their heads

              My blog | My articles | MoXAML PowerToys | Onyx

              1 Reply Last reply
              0
              • T The Man from U N C L E

                Got some interesting responses out of it though. MS does have some good explanations of the reasoning behind each rule, and clearly you have to chose the set for you as some rules don't sit well together. Customising the rules was the second thing I did. It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.

                If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #22

                The Man from U.N.C.L.E. wrote:

                You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.

                Do what I say, not what I do.

                I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Onyx

                1 Reply Last reply
                0
                • J Jeremy Falcon

                  Mr.Prakash wrote:

                  I prefer spaces, when the code is developed with different editors on different platforms, spaces makes the code neater.

                  But, realistically every IDE you'll use allows you to configure tab width.

                  Jeremy Falcon

                  P Offline
                  P Offline
                  Prakash Nadar
                  wrote on last edited by
                  #23

                  Jeremy Falcon wrote:

                  But, realistically every IDE you'll use allows you to configure tab width.

                  Yes it does. the problem is not all spaces can be replaced with tabs while all tabs can be replaced with spaces. What I mean is, some people write it this way enum something { <sp><sp><sp>Enum1, <tab> enum2 } The above code will look different with different settings of tab. If you only have space then there is never a problem. I know I know you will say, why did enum1 had space in the first place. Some devs do it some intentionally and many times accidentally, instead of going after the dev on why he put sp instead of tab. It is easier to say replace all tabs with space. And consider this horrible pattern enum something { <sp><sp><sp><tab>Enum1, <tab> enum2 } With Tab setting to 4, they will look good, if not they will look bad.

                  1 Reply Last reply
                  0
                  • T The Man from U N C L E

                    I know, I can disable rules but that rather defeats the point. I started from the point of how can I be expected to match the rules if the Visual Studio generated code itself does not. As to coding and brackets, I prefer, the following, though I know personal preference and all that.

                    switch (foo){
                    case Bar:
                    RunBar();
                    break;
                    case Foobar:
                    RunFoo();
                    RunBar();
                    break;
                    }

                    In this example Style cop would prefer the following:

                    switch (foo)
                    {
                    case Bar:
                    RunBar();
                    break;
                    case Foobar:
                    RunFoo();
                    RunBar();
                    break;
                    }

                    Who can really say which is more readable, though I would use spaces if pasting on CP because it is easier to type in the editor, that does not allow you to type tabs.

                    If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

                    P Offline
                    P Offline
                    peterchen
                    wrote on last edited by
                    #24

                    There are other scenarios where "inner" tabs would break column alignment. Maybe elastic tabstops[^] would solve the debate (at least for me).

                    Agh! Reality! My Archnemesis![^]
                    | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

                    1 Reply Last reply
                    0
                    • N Nish Nishant

                      The Man from U.N.C.L.E. wrote:

                      It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.

                      Yeah I hear you there. The VS team seems to have been wholly unaware of the StyleCop guidelines :-) BTW, my real name jab was an attempted joke (since you are not using your real name at all)!

                      Regards, Nish


                      My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)

                      T Offline
                      T Offline
                      The Man from U N C L E
                      wrote on last edited by
                      #25

                      Nishant Sivakumar wrote:

                      BTW, my real name jab was an attempted joke (since you are not using your real name at all)!

                      I am on my profile. Or am I? The life of a spy is never simple> :)

                      If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

                      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