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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. The Lounge
  3. This vs. that

This vs. that

Scheduled Pinned Locked Moved The Lounge
csharpphpvisual-studiocomagentic-ai
33 Posts 21 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.
  • Sander RosselS Sander Rossel

    I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

    this.SomeProperty = someValue;
    this.SomeMethod();
    ThisClass.SomeStaticMethod();

    Instead of:

    SomeProperty = someValue;
    SomeMethod();
    SomeStaticMethod();

    My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

    My blog[^]

    public class SanderRossel : Lazy<Person>
    {
    public void DoWork()
    {
    throw new NotSupportedException();
    }
    }

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

    Prefixing this. for members is a Microsoft .NET programming style guideline. I've tried to use it as often as I can remember to.

    Regards, Nish


    Blog: voidnish.wordpress.com

    P 1 Reply Last reply
    0
    • Sander RosselS Sander Rossel

      I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

      this.SomeProperty = someValue;
      this.SomeMethod();
      ThisClass.SomeStaticMethod();

      Instead of:

      SomeProperty = someValue;
      SomeMethod();
      SomeStaticMethod();

      My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

      My blog[^]

      public class SanderRossel : Lazy<Person>
      {
      public void DoWork()
      {
      throw new NotSupportedException();
      }
      }

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #3

      I've gone both ways, and both points are valid. I find myself using this a lot in JavasScript for some reason, but in C# I seldom do. For me, my biggest peeve is inconstancy in a project. So, looks like one of y'all are going to have to give in, or you could have him off'ed.

      Jeremy Falcon

      1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

        this.SomeProperty = someValue;
        this.SomeMethod();
        ThisClass.SomeStaticMethod();

        Instead of:

        SomeProperty = someValue;
        SomeMethod();
        SomeStaticMethod();

        My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

        My blog[^]

        public class SanderRossel : Lazy<Person>
        {
        public void DoWork()
        {
        throw new NotSupportedException();
        }
        }

        M Offline
        M Offline
        Mark_Wallace
        wrote on last edited by
        #4

        I think it's tip 97 in the How to Make C# Look Like Java guide.

        I wanna be a eunuchs developer! Pass me a bread knife!

        1 Reply Last reply
        0
        • Sander RosselS Sander Rossel

          I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

          this.SomeProperty = someValue;
          this.SomeMethod();
          ThisClass.SomeStaticMethod();

          Instead of:

          SomeProperty = someValue;
          SomeMethod();
          SomeStaticMethod();

          My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

          My blog[^]

          public class SanderRossel : Lazy<Person>
          {
          public void DoWork()
          {
          throw new NotSupportedException();
          }
          }

          R Offline
          R Offline
          R Giskard Reventlov
          wrote on last edited by
          #5

          this.Redundant

          K A 2 Replies Last reply
          0
          • Sander RosselS Sander Rossel

            I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

            this.SomeProperty = someValue;
            this.SomeMethod();
            ThisClass.SomeStaticMethod();

            Instead of:

            SomeProperty = someValue;
            SomeMethod();
            SomeStaticMethod();

            My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

            My blog[^]

            public class SanderRossel : Lazy<Person>
            {
            public void DoWork()
            {
            throw new NotSupportedException();
            }
            }

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #6

            I do that. I prefer to type more up front and scratch my head less later. That it honks off some members here is frosting on the cake. :badger:

            1 Reply Last reply
            0
            • Sander RosselS Sander Rossel

              I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

              this.SomeProperty = someValue;
              this.SomeMethod();
              ThisClass.SomeStaticMethod();

              Instead of:

              SomeProperty = someValue;
              SomeMethod();
              SomeStaticMethod();

              My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

              My blog[^]

              public class SanderRossel : Lazy<Person>
              {
              public void DoWork()
              {
              throw new NotSupportedException();
              }
              }

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

              My preference is to never use this unless there is a reason to do so (like conflicting names). My methods are small enough that it is rarely a problem to see what is local and what is a property and anyway, properties begin with a Capital and locals don't. For static methods I use the classname. option, as there is no other obvious differentiator. That said, I don't work with many classes with static methods, so not something I have formed a habit out of. When I see this.SomeProperty = this.SomeMethod(this.SomeOtherProperty) I cringe, and think "this? What else?)

              PooperPig - Coming Soon

              S 1 Reply Last reply
              0
              • Sander RosselS Sander Rossel

                I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

                this.SomeProperty = someValue;
                this.SomeMethod();
                ThisClass.SomeStaticMethod();

                Instead of:

                SomeProperty = someValue;
                SomeMethod();
                SomeStaticMethod();

                My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

                My blog[^]

                public class SanderRossel : Lazy<Person>
                {
                public void DoWork()
                {
                throw new NotSupportedException();
                }
                }

                S Offline
                S Offline
                Super Lloyd
                wrote on last edited by
                #8

                I do that sometimes.... And I don't really care either way... And sometimes it's necessary when function parameter has the same name as class field!

                My programming get away... The Blog... DirectX for WinRT/C# since 2013! Taking over the world since 1371!

                1 Reply Last reply
                0
                • N Nish Nishant

                  Prefixing this. for members is a Microsoft .NET programming style guideline. I've tried to use it as often as I can remember to.

                  Regards, Nish


                  Blog: voidnish.wordpress.com

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #9

                  Got a link?

                  N 2 Replies Last reply
                  0
                  • Sander RosselS Sander Rossel

                    I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

                    this.SomeProperty = someValue;
                    this.SomeMethod();
                    ThisClass.SomeStaticMethod();

                    Instead of:

                    SomeProperty = someValue;
                    SomeMethod();
                    SomeStaticMethod();

                    My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

                    My blog[^]

                    public class SanderRossel : Lazy<Person>
                    {
                    public void DoWork()
                    {
                    throw new NotSupportedException();
                    }
                    }

                    S Offline
                    S Offline
                    Sanjay K Gupta
                    wrote on last edited by
                    #10

                    I do not care about these redundancy but, personally, I do not prefer these type of redundant code.

                    ___ ___ ___
                    |__ |_| |\ | | |_| \ /
                    __| | | | \| |__| | | /

                    1 Reply Last reply
                    0
                    • Sander RosselS Sander Rossel

                      I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

                      this.SomeProperty = someValue;
                      this.SomeMethod();
                      ThisClass.SomeStaticMethod();

                      Instead of:

                      SomeProperty = someValue;
                      SomeMethod();
                      SomeStaticMethod();

                      My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

                      My blog[^]

                      public class SanderRossel : Lazy<Person>
                      {
                      public void DoWork()
                      {
                      throw new NotSupportedException();
                      }
                      }

                      N Offline
                      N Offline
                      Nareesh1
                      wrote on last edited by
                      #11

                      By that same reasoning, stop using any "using" and reference only via fully qualified "System.Windows.Forms.ListCtrl.Item item" :rolleyes: who needs any shortening of a line, just buy BLACK FRIDAY 50" MONITOR THATS IT?

                      A Sander RosselS 3 Replies Last reply
                      0
                      • Sander RosselS Sander Rossel

                        I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

                        this.SomeProperty = someValue;
                        this.SomeMethod();
                        ThisClass.SomeStaticMethod();

                        Instead of:

                        SomeProperty = someValue;
                        SomeMethod();
                        SomeStaticMethod();

                        My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

                        My blog[^]

                        public class SanderRossel : Lazy<Person>
                        {
                        public void DoWork()
                        {
                        throw new NotSupportedException();
                        }
                        }

                        J Offline
                        J Offline
                        Jorgen Andersson
                        wrote on last edited by
                        #12

                        Whenever there is the slightest chance of ambiguity, otherwise i prefer to keep it short.

                        Wrong is evil and must be defeated. - Jeff Ello (√-shit)2

                        1 Reply Last reply
                        0
                        • N Nareesh1

                          By that same reasoning, stop using any "using" and reference only via fully qualified "System.Windows.Forms.ListCtrl.Item item" :rolleyes: who needs any shortening of a line, just buy BLACK FRIDAY 50" MONITOR THATS IT?

                          A Offline
                          A Offline
                          Agent__007
                          wrote on last edited by
                          #13

                          Nareesh1 wrote:

                          fully qualified "System.Windows.Forms.ListCtrl.Item item"

                          Even when you say "fully qualified", there is no such thing as "System.Windows.Forms.ListCtrl.Item".. :laugh:

                          Your time will come, if you let it be right.

                          1 Reply Last reply
                          0
                          • N Nareesh1

                            By that same reasoning, stop using any "using" and reference only via fully qualified "System.Windows.Forms.ListCtrl.Item item" :rolleyes: who needs any shortening of a line, just buy BLACK FRIDAY 50" MONITOR THATS IT?

                            A Offline
                            A Offline
                            Agent__007
                            wrote on last edited by
                            #14

                            Nareesh1 wrote:

                            fully qualified "System.Windows.Forms.ListCtrl.Item item"

                            Even when you say "fully qualified", there is no such thing as "System.Windows.Forms.ListCtrl.Item".. :laugh:

                            Nareesh1 wrote:

                            who needs any shortening of a line

                            Oh the irony! :laugh:

                            Your time will come, if you let it be right.

                            1 Reply Last reply
                            0
                            • Sander RosselS Sander Rossel

                              I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

                              this.SomeProperty = someValue;
                              this.SomeMethod();
                              ThisClass.SomeStaticMethod();

                              Instead of:

                              SomeProperty = someValue;
                              SomeMethod();
                              SomeStaticMethod();

                              My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

                              My blog[^]

                              public class SanderRossel : Lazy<Person>
                              {
                              public void DoWork()
                              {
                              throw new NotSupportedException();
                              }
                              }

                              V Offline
                              V Offline
                              V 0
                              wrote on last edited by
                              #15

                              Unless I have a construct like:

                              public class X{
                              private int number;

                              public X(int number){
                              this.number = number;
                              }
                              }

                              I rarely uses this.

                              V.
                              (MQOTD rules and previous solutions)

                              1 Reply Last reply
                              0
                              • Sander RosselS Sander Rossel

                                I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

                                this.SomeProperty = someValue;
                                this.SomeMethod();
                                ThisClass.SomeStaticMethod();

                                Instead of:

                                SomeProperty = someValue;
                                SomeMethod();
                                SomeStaticMethod();

                                My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

                                My blog[^]

                                public class SanderRossel : Lazy<Person>
                                {
                                public void DoWork()
                                {
                                throw new NotSupportedException();
                                }
                                }

                                R Offline
                                R Offline
                                R Erasmus
                                wrote on last edited by
                                #16

                                I would say to use the property assignment 'this' in the following scenario:

                                void foo(int someValue)
                                {
                                this.someValue = someValue;
                                this.SomeMethod(AnotherClass.SomeMethod());
                                }

                                But not in the following scenario:

                                void foo()
                                {
                                someValue = 5;
                                SomeMethod(5);
                                }

                                With ThisClass.SomeStaticMethod() I'd always use is as you did unless of course you are using the static method of the class you are working in, then I'd just use SomeStaticMethod.

                                "Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>

                                1 Reply Last reply
                                0
                                • R R Giskard Reventlov

                                  this.Redundant

                                  K Offline
                                  K Offline
                                  Keith Barrow
                                  wrote on last edited by
                                  #17

                                  Errrm, this.

                                  Alberto Brandolini:

                                  The amount of energy necessary to refute bullshit is an order of magnitude bigger than to produce it.

                                  1 Reply Last reply
                                  0
                                  • R R Giskard Reventlov

                                    this.Redundant

                                    A Offline
                                    A Offline
                                    Agent__007
                                    wrote on last edited by
                                    #18

                                    Only assignment, call, increment, decrement, and new object expressions can be used as a statement. :)

                                    Your time will come, if you let it be right.

                                    1 Reply Last reply
                                    0
                                    • Sander RosselS Sander Rossel

                                      I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

                                      this.SomeProperty = someValue;
                                      this.SomeMethod();
                                      ThisClass.SomeStaticMethod();

                                      Instead of:

                                      SomeProperty = someValue;
                                      SomeMethod();
                                      SomeStaticMethod();

                                      My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

                                      My blog[^]

                                      public class SanderRossel : Lazy<Person>
                                      {
                                      public void DoWork()
                                      {
                                      throw new NotSupportedException();
                                      }
                                      }

                                      N Offline
                                      N Offline
                                      Nagy Vilmos
                                      wrote on last edited by
                                      #19

                                      this is good and I use it normally. The fact that it seems to annoy some pooples just encourages me to use it more. :-D

                                      S 1 Reply Last reply
                                      0
                                      • Sander RosselS Sander Rossel

                                        I have a question about your preferred programming style. Whenever I write code in C# I make extensive use of the 'this' keyword and I use class names when referencing statics. So:

                                        this.SomeProperty = someValue;
                                        this.SomeMethod();
                                        ThisClass.SomeStaticMethod();

                                        Instead of:

                                        SomeProperty = someValue;
                                        SomeMethod();
                                        SomeStaticMethod();

                                        My reasoning behind this is that I can tell something is an instance method or a static method. And to be completely honest it's also something I started doing in VB because VB has Modules and Modules don't make you specify the Module's name. So Me.SomeMethod() can be an instance method, a Shared/static method on the current class or a method in some Module! Now there's a new guy at work and he really hates this style of programming because he thinks it's redundant. I'm not asking for right or wrong (unless I'm the one who's right ;p), but I want to know personal preferences.

                                        My blog[^]

                                        public class SanderRossel : Lazy<Person>
                                        {
                                        public void DoWork()
                                        {
                                        throw new NotSupportedException();
                                        }
                                        }

                                        D Offline
                                        D Offline
                                        den2k88
                                        wrote on last edited by
                                        #20

                                        "this." triggers any auto-completion or Intellisense in the world. Yes I'm lazy - I wouldn't train machines to do men's work if I wasn't ;)

                                        F 1 Reply Last reply
                                        0
                                        • L Lost User

                                          My preference is to never use this unless there is a reason to do so (like conflicting names). My methods are small enough that it is rarely a problem to see what is local and what is a property and anyway, properties begin with a Capital and locals don't. For static methods I use the classname. option, as there is no other obvious differentiator. That said, I don't work with many classes with static methods, so not something I have formed a habit out of. When I see this.SomeProperty = this.SomeMethod(this.SomeOtherProperty) I cringe, and think "this? What else?)

                                          PooperPig - Coming Soon

                                          S Offline
                                          S Offline
                                          Slacker007
                                          wrote on last edited by
                                          #21

                                          _Maxxx_ wrote:

                                          (like conflicting names)

                                          :thumbsup::thumbsup::thumbsup:

                                          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