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
    Le centriste
    wrote on last edited by
    #18

    I would be more concern of naming a member variable "k". Why do you hate "this" so much?

    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

      M Offline
      M Offline
      Member 96
      wrote on last edited by
      #19

      Almost certainly it's to kick in intellisense. I do it all the time; it's a form of insurance to gurantee you are typing the correct variable name. At worst it's a difference of esthetics, it makes no other difference.


      "It's so simple to be wise. Just think of something stupid to say and then don't say it." -Sam Levenson

      1 Reply Last reply
      0
      • S Shog9 0

        I think his complaint is that this.k could be easily written simply as k. Although yes, k is a terrible name for a class member.

        ----

        You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

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

        Shog9 wrote:

        Although yes, k is a terrible name for a class member.

        In the context of the class, it makes sense. Combinations(n, k), where "n" and "k" are the common math terms for these concepts. Marc

        Thyme In The Country Interacx My Blog

        1 Reply Last reply
        0
        • S StevenWalsh

          i use letters all the time for couters in a for loop, do you hate that?

          for(int i = 0; i < this.k; i++){
          MarcClifton.Anger++;
          }

          Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer. -Fred Brooks

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

          StevenWalsh wrote:

          i use letters all the time for couters in a for loop, do you hate that?

          I do that all the time. And I start with "i", harking back to the days of Fortran, where "i" was the first of several letters that defaulted to integer type. Pretty crazy. Marc

          Thyme In The Country Interacx My Blog

          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

            S Offline
            S Offline
            Single Step Debugger
            wrote on last edited by
            #22

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

              A Offline
              A Offline
              Adam Maras
              wrote on last edited by
              #23

              Uh... those of you that are playing the IntelliSense card... Alt+Right Arrow is your friend ;)

              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

                J Offline
                J Offline
                jbarton
                wrote on last edited by
                #24

                I am not a fan of "this." as a prefix (coming from a C++ background). The place that I work at does new development in C# and has decided to use the Microsoft StyleCop to check the code style. One of the rules of the StyleCop is that member access must be prefixed by "this.". Apparently this is the Microsoft recommended way of indicating member variable access. John

                K 1 Reply Last reply
                0
                • S Shog9 0

                  I've seen comments... probably here... from folk who use it to make it obvious they're using member variables (replacing the old m_ prefix, essentially). I don't care for it either.

                  ----

                  You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

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

                  Shog9 wrote:

                  I don't care for it either.

                  Microsoft StyleCop enforces use of this on private members. StyleCop is being adopted more and more within Microsoft so expect more of it going forward. To be honest I don't care much either way - though to date I've used the _ for private fields.

                  Kevin

                  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

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #26

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

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

                    P 1 Reply Last reply
                    0
                    • J jbarton

                      I am not a fan of "this." as a prefix (coming from a C++ background). The place that I work at does new development in C# and has decided to use the Microsoft StyleCop to check the code style. One of the rules of the StyleCop is that member access must be prefixed by "this.". Apparently this is the Microsoft recommended way of indicating member variable access. John

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

                      jbarton wrote:

                      Apparently this is the Microsoft recommended way of indicating member variable access.

                      Basically, StyleCop is being used more and more across Microsoft teams so expect more of it going forward. It's the Java house style btw. Note that StyleCop is customisable though. You can disable that rule for your team.

                      Kevin

                      J 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

                        R Offline
                        R Offline
                        Ri Qen Sin
                        wrote on last edited by
                        #28

                        I simply use it because it helps me figure out what's a class member or not, although laziness is also a good justification. :)

                        So the creationist says: Everything must have a designer. God designed everything. I say: Why is God the only exception? Why not make the "designs" (like man) exceptions and make God a creation of man?

                        1 Reply Last reply
                        0
                        • K Kevin McFarlane

                          jbarton wrote:

                          Apparently this is the Microsoft recommended way of indicating member variable access.

                          Basically, StyleCop is being used more and more across Microsoft teams so expect more of it going forward. It's the Java house style btw. Note that StyleCop is customisable though. You can disable that rule for your team.

                          Kevin

                          J Offline
                          J Offline
                          jbarton
                          wrote on last edited by
                          #29

                          I wish I could disable this warning. It was a decision from higher up that StyleCop would be used pretty much as is (a few warnings have been turned off, but for the most part they are all on). There is a check-in policy that says that there can't be any StyleCop warnings based on the global team settings. I can't turn it off just for my machine or I would get warnings and the check-in would fail.

                          K 1 Reply Last reply
                          0
                          • J jbarton

                            I wish I could disable this warning. It was a decision from higher up that StyleCop would be used pretty much as is (a few warnings have been turned off, but for the most part they are all on). There is a check-in policy that says that there can't be any StyleCop warnings based on the global team settings. I can't turn it off just for my machine or I would get warnings and the check-in would fail.

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

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

                            Kevin

                            T 1 Reply Last reply
                            0
                            • D Dan Neely

                              In vs2k3, intilisense didn't start as soon as you began typing. IF you weren't sure what the variable was called you had to type this. to make it come up. Not needed int 2k8, I never used 2k5; could just be an old bad habit.

                              Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall

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

                              In 2k5 it also immediately comes up

                              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

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