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. Why does C# programmers use

Why does C# programmers use

Scheduled Pinned Locked Moved The Lounge
questioncsharpc++com
25 Posts 16 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.
  • J Jorgen Sigvardsson

    this excessively? this.var = some_value; this.SomeMethod(); // yadda yadda, etc, and so forth Why? Is there some scoping rule in C# that I am not yet aware of? Last time I fiddled with C# my brain used "ordinary C++" scoping rules - and it worked. Sonorked as well: 100.13197 jorgen FreeBSD is sexy.

    G Offline
    G Offline
    G Suresh
    wrote on last edited by
    #2

    It is rather nice to use 'this' if you are not using the Hungarian notation. You can readily distinguish members. Another reason is that you get Intellisense support for members of the current class. Regards, Suresh

    N R J 3 Replies Last reply
    0
    • J Jorgen Sigvardsson

      this excessively? this.var = some_value; this.SomeMethod(); // yadda yadda, etc, and so forth Why? Is there some scoping rule in C# that I am not yet aware of? Last time I fiddled with C# my brain used "ordinary C++" scoping rules - and it worked. Sonorked as well: 100.13197 jorgen FreeBSD is sexy.

      R Offline
      R Offline
      Rama Krishna Vavilala
      wrote on last edited by
      #3

      I just coded a line in one of the constuctors like this and saw you mail. What a coincidence? It is something which is coming from java. I do this a lot often in my constructors for obvious reasons. Ofcourse Suresh has more valid points. public Item(string name, string summary) { this.name = name; this.summary = summary; }

      1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        this excessively? this.var = some_value; this.SomeMethod(); // yadda yadda, etc, and so forth Why? Is there some scoping rule in C# that I am not yet aware of? Last time I fiddled with C# my brain used "ordinary C++" scoping rules - and it worked. Sonorked as well: 100.13197 jorgen FreeBSD is sexy.

        J Offline
        J Offline
        Jamie Nordmeyer
        wrote on last edited by
        #4

        Frankly, I agree with you Jorgen. We use VB.NET (be nice ;) ) where I work, and I'm the only programmer who never uses 'Me' (VB's equivelant of 'this'). It looks less muddled. Jamie Nordmeyer Portland, Oregon, USA

        1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          this excessively? this.var = some_value; this.SomeMethod(); // yadda yadda, etc, and so forth Why? Is there some scoping rule in C# that I am not yet aware of? Last time I fiddled with C# my brain used "ordinary C++" scoping rules - and it worked. Sonorked as well: 100.13197 jorgen FreeBSD is sexy.

          B Offline
          B Offline
          Brian Delahunty
          wrote on last edited by
          #5

          I do agree that freebsd is sexy... :rose: I agree with you about the scopeing. But can't you do it both wasys in c#


          "Never tell people how to do things. Tell them what to do, and they will surprise you with their ingenuity." - General George S. Patton Jr.

          1 Reply Last reply
          0
          • J Jorgen Sigvardsson

            this excessively? this.var = some_value; this.SomeMethod(); // yadda yadda, etc, and so forth Why? Is there some scoping rule in C# that I am not yet aware of? Last time I fiddled with C# my brain used "ordinary C++" scoping rules - and it worked. Sonorked as well: 100.13197 jorgen FreeBSD is sexy.

            K Offline
            K Offline
            Konstantin Vasserman
            wrote on last edited by
            #6

            When I can't remember the name of a member I type this. to get IntelliSense to help me. Then I go back and remove this.. I don't know why I do that. I guess, this just doesn't look good for some strange reason... :confused:

            C 1 Reply Last reply
            0
            • K Konstantin Vasserman

              When I can't remember the name of a member I type this. to get IntelliSense to help me. Then I go back and remove this.. I don't know why I do that. I guess, this just doesn't look good for some strange reason... :confused:

              C Offline
              C Offline
              Chris Maunder
              wrote on last edited by
              #7

              I'm with you, Konstantin. Superflous this's make me shudder. I will probably be scorned by the masses, but I'm going to continue using 'm_' prefixes for my member variables. cheers, Chris Maunder

              J K S A J 5 Replies Last reply
              0
              • C Chris Maunder

                I'm with you, Konstantin. Superflous this's make me shudder. I will probably be scorned by the masses, but I'm going to continue using 'm_' prefixes for my member variables. cheers, Chris Maunder

                J Offline
                J Offline
                Jason Hooper
                wrote on last edited by
                #8

                Is that more because of the force of habit, or does a need remain for the use of the m_ prefix to clarify things or help you write better code? I'm 50/50 on the matter; I've never collaborated on a project with others or worked as part of a team, so I tend to just do whatever I feel like doing at the time. - Jason (SonorkID 100.611) Veni, vidi, VC       - I came, I saw, Visual C

                C 1 Reply Last reply
                0
                • C Chris Maunder

                  I'm with you, Konstantin. Superflous this's make me shudder. I will probably be scorned by the masses, but I'm going to continue using 'm_' prefixes for my member variables. cheers, Chris Maunder

                  K Offline
                  K Offline
                  Konstantin Vasserman
                  wrote on last edited by
                  #9

                  m_Hmm ;)

                  J C 2 Replies Last reply
                  0
                  • K Konstantin Vasserman

                    m_Hmm ;)

                    J Offline
                    J Offline
                    Jason Hooper
                    wrote on last edited by
                    #10

                    m_cHammer :) I actually used m_cHandle the other day and it reminded me of him - Jason (SonorkID 100.611) Veni, vidi, VC       - I came, I saw, Visual C

                    A 1 Reply Last reply
                    0
                    • K Konstantin Vasserman

                      m_Hmm ;)

                      C Offline
                      C Offline
                      Chris Maunder
                      wrote on last edited by
                      #11

                      lol. Good one. cheers, Chris Maunder

                      1 Reply Last reply
                      0
                      • J Jason Hooper

                        m_cHammer :) I actually used m_cHandle the other day and it reminded me of him - Jason (SonorkID 100.611) Veni, vidi, VC       - I came, I saw, Visual C

                        A Offline
                        A Offline
                        Alvaro Mendez
                        wrote on last edited by
                        #12

                        :laugh: m_cHammer.cantTouch(this); Regards, Alvaro A priest, a minister and a rabbi walk into a bar. The bartender says, "What is this, a joke?"

                        K 1 Reply Last reply
                        0
                        • C Chris Maunder

                          I'm with you, Konstantin. Superflous this's make me shudder. I will probably be scorned by the masses, but I'm going to continue using 'm_' prefixes for my member variables. cheers, Chris Maunder

                          S Offline
                          S Offline
                          Simon Walton
                          wrote on last edited by
                          #13

                          Damn you VS.NET owners. Don't you realise that VS6 users are superior? Simon If I type UpdataData(FALSE) instead of UpdateData(FALSE) once more... Sonork ID 100.10024

                          C 1 Reply Last reply
                          0
                          • J Jason Hooper

                            Is that more because of the force of habit, or does a need remain for the use of the m_ prefix to clarify things or help you write better code? I'm 50/50 on the matter; I've never collaborated on a project with others or worked as part of a team, so I tend to just do whatever I feel like doing at the time. - Jason (SonorkID 100.611) Veni, vidi, VC       - I came, I saw, Visual C

                            C Offline
                            C Offline
                            Chris Maunder
                            wrote on last edited by
                            #14

                            In situations like

                            class Foo
                            {
                            protected int Field;
                            void SetField(int Field)
                            {
                            this.Field = Field;
                            }
                            }

                            Gives me the heeby jeebies. I prefer

                            class Foo
                            {
                            protected int m_iField;
                            void SetField(int Field)
                            {
                            m_iField = Field;
                            }
                            }

                            By using Hungarian in your member variables you are also never tempted to have:

                            class Foo
                            {
                            public int Field;
                            ...
                            }

                            (ie publicly accessible member variables). Sometimes public access to fields is fine (eg simple structures like points) but C# provides for properties which adds a level of future-proofing (and encapsulation) that I've found invaluable cheers, Chris Maunder

                            1 Reply Last reply
                            0
                            • J Jorgen Sigvardsson

                              this excessively? this.var = some_value; this.SomeMethod(); // yadda yadda, etc, and so forth Why? Is there some scoping rule in C# that I am not yet aware of? Last time I fiddled with C# my brain used "ordinary C++" scoping rules - and it worked. Sonorked as well: 100.13197 jorgen FreeBSD is sexy.

                              D Offline
                              D Offline
                              Daniel Ferguson
                              wrote on last edited by
                              #15

                              It sounds to me a bit like putting 'Earth' at the end of your own address. :| "I've read the Bible through a couple of times and it is a nice collection of morality stories and adventure fiction. Sort of like Huck Finn and Tom Sawyer except without the laughs." -- Michael P Butler 14 Mar '02

                              D 1 Reply Last reply
                              0
                              • D Daniel Ferguson

                                It sounds to me a bit like putting 'Earth' at the end of your own address. :| "I've read the Bible through a couple of times and it is a nice collection of morality stories and adventure fiction. Sort of like Huck Finn and Tom Sawyer except without the laughs." -- Michael P Butler 14 Mar '02

                                D Offline
                                D Offline
                                David Wulff
                                wrote on last edited by
                                #16

                                Daniel Ferguson wrote: It sounds to me a bit like putting 'Earth' at the end of your own address. That's what I do on things like CV's, quotes, etc. It may sound stupid (and childish), but I don't want to work with anyone who does not have enough of a sense of humour to appreciate that. So far it has worked to my advantage too.


                                David Wulff http://www.davidwulff.co.uk (updated) I could have created a cool signature brought to life with complex interactive DHTML, but I don't like to show off.

                                1 Reply Last reply
                                0
                                • G G Suresh

                                  It is rather nice to use 'this' if you are not using the Hungarian notation. You can readily distinguish members. Another reason is that you get Intellisense support for members of the current class. Regards, Suresh

                                  N Offline
                                  N Offline
                                  Nemanja Trifunovic
                                  wrote on last edited by
                                  #17

                                  Exactly. That's why I often use it, even with C++. We don't use Hungarian notation where I work, and this is a little "workaround". I vote pro drink :beer:

                                  1 Reply Last reply
                                  0
                                  • J Jorgen Sigvardsson

                                    this excessively? this.var = some_value; this.SomeMethod(); // yadda yadda, etc, and so forth Why? Is there some scoping rule in C# that I am not yet aware of? Last time I fiddled with C# my brain used "ordinary C++" scoping rules - and it worked. Sonorked as well: 100.13197 jorgen FreeBSD is sexy.

                                    J Offline
                                    J Offline
                                    Jarek G
                                    wrote on last edited by
                                    #18

                                    Its a standard notation in oop languages a specially in Java and C# you are using namespacing in c# and in your namespace you might have some int or.. that have the same name but don't belong to the class?? The other thing is when you using this. you get intelihelp from Visual Studio :-) /Jarek "Imagination is more important than knowledge, for knowledge is limited while imagination embraces the entire world." -Albert Einstein

                                    J 1 Reply Last reply
                                    0
                                    • S Simon Walton

                                      Damn you VS.NET owners. Don't you realise that VS6 users are superior? Simon If I type UpdataData(FALSE) instead of UpdateData(FALSE) once more... Sonork ID 100.10024

                                      C Offline
                                      C Offline
                                      Chris Maunder
                                      wrote on last edited by
                                      #19

                                      Simon Walton wrote: If I type UpdataData(FALSE) instead of UpdateData(FALSE) once more... ROTFL!! How many times have I done that...:rolleyes: cheers, Chris Maunder

                                      1 Reply Last reply
                                      0
                                      • A Alvaro Mendez

                                        :laugh: m_cHammer.cantTouch(this); Regards, Alvaro A priest, a minister and a rabbi walk into a bar. The bartender says, "What is this, a joke?"

                                        K Offline
                                        K Offline
                                        Konstantin Vasserman
                                        wrote on last edited by
                                        #20

                                        LOL. :laugh:

                                        1 Reply Last reply
                                        0
                                        • C Chris Maunder

                                          I'm with you, Konstantin. Superflous this's make me shudder. I will probably be scorned by the masses, but I'm going to continue using 'm_' prefixes for my member variables. cheers, Chris Maunder

                                          A Offline
                                          A Offline
                                          Atlantys
                                          wrote on last edited by
                                          #21

                                          it's all about the "m_" ;P it just makes sense.

                                          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