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. this (another C# programmer rant)

this (another C# programmer rant)

Scheduled Pinned Locked Moved The Lounge
csharpvisual-studiocomquestion
41 Posts 26 Posters 8 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.
  • M Marc Clifton

    Code:

    	public override string ToString()
    	{
    		string s = String.Empty;
    
    		for (long i = 0; i < this.k; ++i)
    		{
    			s += this.data\[i\].ToString() + " ";
    		}
    
    		return s;
    	} // ToString()
    

    I HATE WHEN PROGRAMMERS USE THIS. this.k??? Give me a FB!!!! That doesn't even make sense from a "I'm saving keystrokes by prefixing with "this." so Intellisense kicks in." Marc

    Thyme In The Country Interacx My Blog

    L Offline
    L Offline
    leppie
    wrote on last edited by
    #32

    Man that is ugly code! Grrrrrr. Why do people never use string.Join ?

    xacc.ide - now with TabsToSpaces support
    IronScheme - 1.0 alpha 4a out now (29 May 2008)
    ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

    1 Reply Last reply
    0
    • K Kevin McFarlane

      Too bad for you. Personally I'm not much fussed by this rule. There are many things that irritate me more. :)

      Kevin

      T Offline
      T Offline
      TheCardinal
      wrote on last edited by
      #33

      i dont know why stylecop is pushing the "this." rule, while Resharper always yell at you when you do so.

      Life - Dreams = Job TheCardinal CTC-RDG

      K 1 Reply Last reply
      0
      • M Mark Salsbery

        Visual Studio generated code uses it everywhere. Drives me nuts coming from a C++ background.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        P Offline
        P Offline
        Pawel Krakowiak
        wrote on last edited by
        #34

        Mark Salsbery wrote:

        Visual Studio generated code uses it everywhere.

        Designer files look like a Christmas tree when running ReSharper (full of warning notifications). :P

        1 Reply Last reply
        0
        • M Marc Clifton

          Code:

          	public override string ToString()
          	{
          		string s = String.Empty;
          
          		for (long i = 0; i < this.k; ++i)
          		{
          			s += this.data\[i\].ToString() + " ";
          		}
          
          		return s;
          	} // ToString()
          

          I HATE WHEN PROGRAMMERS USE THIS. this.k??? Give me a FB!!!! That doesn't even make sense from a "I'm saving keystrokes by prefixing with "this." so Intellisense kicks in." Marc

          Thyme In The Country Interacx My Blog

          P Offline
          P Offline
          Pawel Krakowiak
          wrote on last edited by
          #35

          I admit I was doing this as well when I started C# programming. Now I'm running ReSharper and it marks this keyword use as a warning so I clean them up whenever I find them in my old code. One use is when a private field has the same name as a constructor parameter, e.g.

          public class A
          {
          private string name;

          public A (string name)
          {
              //name = name; // ERROR
              this.name = name; // OK!
          }
          

          }

          But of course this means you need some naming conventions. ;)

          M 1 Reply Last reply
          0
          • T TheCardinal

            i dont know why stylecop is pushing the "this." rule, while Resharper always yell at you when you do so.

            Life - Dreams = Job TheCardinal CTC-RDG

            K Offline
            K Offline
            Kevin McFarlane
            wrote on last edited by
            #36

            I don't think it should be mandated. But OTOH why would Resharper explicitly reject it? What's their rationale?

            Kevin

            T 1 Reply Last reply
            0
            • K Kevin McFarlane

              I don't think it should be mandated. But OTOH why would Resharper explicitly reject it? What's their rationale?

              Kevin

              T Offline
              T Offline
              TheCardinal
              wrote on last edited by
              #37

              dont know about jetbrain stand about it...maybe thats why they flag it as a warning. for me its a personal choice ;)

              Life - Dreams = Job TheCardinal CTC-RDG

              1 Reply Last reply
              0
              • P Pawel Krakowiak

                I admit I was doing this as well when I started C# programming. Now I'm running ReSharper and it marks this keyword use as a warning so I clean them up whenever I find them in my old code. One use is when a private field has the same name as a constructor parameter, e.g.

                public class A
                {
                private string name;

                public A (string name)
                {
                    //name = name; // ERROR
                    this.name = name; // OK!
                }
                

                }

                But of course this means you need some naming conventions. ;)

                M Offline
                M Offline
                Marc Clifton
                wrote on last edited by
                #38

                Pawel Krakowiak wrote:

                One use is when a private field has the same name as a constructor parameter, e.g.

                Which is the only time I use this. Marc

                Thyme In The Country Interacx My Blog

                P 1 Reply Last reply
                0
                • M Marc Clifton

                  Pawel Krakowiak wrote:

                  One use is when a private field has the same name as a constructor parameter, e.g.

                  Which is the only time I use this. Marc

                  Thyme In The Country Interacx My Blog

                  P Offline
                  P Offline
                  Pawel Krakowiak
                  wrote on last edited by
                  #39

                  Marc Clifton wrote:

                  Which is the only time I use this.

                  Wouldn't it be better though to name the fields differently? I prefix all private fields with an underscore _. Um, I'm not looking to start that debate again. :P

                  M 1 Reply Last reply
                  0
                  • P Pawel Krakowiak

                    Marc Clifton wrote:

                    Which is the only time I use this.

                    Wouldn't it be better though to name the fields differently? I prefix all private fields with an underscore _. Um, I'm not looking to start that debate again. :P

                    M Offline
                    M Offline
                    Marc Clifton
                    wrote on last edited by
                    #40

                    Pawel Krakowiak wrote:

                    I prefix all private fields with an underscore _. Um, I'm not looking to start that debate again. :P

                    hehe. I personally don't like underscores, but at least I'm consistent in how I write my classes. :) Marc

                    Thyme In The Country Interacx My Blog

                    1 Reply Last reply
                    0
                    • S Single Step Debugger

                      No C++ programmers in that thread. This.IsGreat(true); Personally, I really hate to see “::someMetod() “ in the code. Why it is so difficult for someone to type the base class name?!? - especially if you have a multiple inheritance.

                      The narrow specialist in the broad sense of the word is a complete idiot in the narrow sense of the word. Advertise here – minimum three posts per day are guaranteed.

                      modified on Thursday, September 18, 2008 2:19 PM

                      S Offline
                      S Offline
                      shiftedbitmonkey
                      wrote on last edited by
                      #41

                      Deyan Georgiev wrote:

                      Personally, I really hate to see “::someMetod() “ in the code.

                      That's not how the scope resolution operator is behaving in this instance. This usage says to look outside the class for resolution. So, if you're using a file function called: open, and you have a member of your class called open, and you want to open a file you'd prefix it as: ::open which would call the c function and not the C++ method.

                      I've heard more said about less.

                      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