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. What do you think?

What do you think?

Scheduled Pinned Locked Moved The Lounge
questiondatabasesql-servercomsysadmin
94 Posts 67 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.
  • R Rocky Moore

    Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

    Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

    S Offline
    S Offline
    Stuart Dootson
    wrote on last edited by
    #32

    I use '_' as a suffix for private member data (which means either all member data of a class or none of it) in C++. However, the rest of the naming is camel-case (capitalized for functions and classes):

    class SampleClass
    {
    public:
       int SomeMethod() const;
    private:
       int aDataMember_;
    };
    
    R 1 Reply Last reply
    0
    • A Aaron VanWieren

      Can't stand _them. Sorry to butt in on this, but this is one thing I truly hate. Isn't this part of or all of the Hungarian notation? Which has historical roots in early programming?

      C Offline
      C Offline
      Chris_Green
      wrote on last edited by
      #33

      You'll love this: I use both, but consistently. Any variable which belong in the header file is prefixed with m_ Any control is prefixed with _TypeDescriptor such as _EditTest or _ButtonGo. It does make working with the code, especially via IntelliSense, remarkably easy. All the variables are nicely grouped. And all the controls are grouped separately and sorted by type.

      1 Reply Last reply
      0
      • J JimmyRopes

        Christian Graus wrote:

        No

        Did you mean strNo? :~

        Simply Elegant Designs JimmyRopes Designs
        Think inside the box! ProActive Secure Systems
        I'm on-line therefore I am. JimmyRopes

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

        JimmyRopes wrote:

        Did you mean strNo?

        Surely it's lpszNo.

        the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
        Deja View - the feeling that you've seen this post before.

        1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          Rocky Moore wrote:

          So, what you think?

          Personally, I like the m_ prefix. But I can deal with pretty much anything, as long as it's consistent.

          -- Not based on the Novel by James Fenimore Cooper

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

          Same here.

          The tigress is here :-D

          1 Reply Last reply
          0
          • R Rocky Moore

            Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

            Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

            B Offline
            B Offline
            Bogdan Damian
            wrote on last edited by
            #36

            I use it only this notation for private vars from classes :)

            damianbc Developer

            1 Reply Last reply
            0
            • T Tim Craig

              No! And I don't like seeing it on members in public either. ;P

              The evolution of the human genome is too important to be left to chance idiots like CSS.

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #37

              Tim Craig wrote:

              The evolution of the human genome is too important to be left to chance idiots like CSS.

              Does that qualify as meta-evolution? :)

              -- Verletzen zerfetzen zersetzen zerstören Doch es darf nicht mir gehören Ich muss zerstören

              1 Reply Last reply
              0
              • T Taka Muraoka

                Rocky Moore wrote:

                Do you use/like the "_" to prefix private members?

                IIRC, symbols with a leading _ are reserved for the system. This is for C but probably carried over to C++, although it probably doesn't apply for class members. It'd be dumb to use them, though, quite apart from the fact it looks butt-ugly. I always used to use "m_" for member variables and hated it, until I had an epiphany and saw someone using just "m" (e.g. mMemberVariable). So much nicer :cool:


                0 bottles of beer on the wall, 0 bottles of beer, you take 1 down, pass it around, 4294967295 bottles of beer on the wall. Awasu 2.2.4 [^]: A free RSS/Atom feed reader with support for Code Project.

                M Offline
                M Offline
                Mike Dimmick
                wrote on last edited by
                #38

                Various C++ authors suggest using a trailing underscore for a member variable, but that's even worse, IMO - especially when it's a pointer, since you have to release Shift in order to dereference (to type the '-' of ->).

                Stability. What an interesting concept. -- Chris Maunder

                1 Reply Last reply
                0
                • R Rocky Moore

                  Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

                  Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

                  B Offline
                  B Offline
                  beatle11
                  wrote on last edited by
                  #39

                  Well I like using some prefix. either 'm_' or just the '_'. With C++ for example you can use the 'this' keyword to differentiate but i find it more annoying and confusing to read code this way as I'm sure many programmers do.

                  R 1 Reply Last reply
                  0
                  • R Rocky Moore

                    Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

                    Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

                    C Offline
                    C Offline
                    Claus Brinch Jensen
                    wrote on last edited by
                    #40

                    Personally I love using the '_' prefix. It tells you instantly that you are dealing with a private member variable and it doesn't decrease readability at all, IMO. In fact, I have always preferred lower-case underscored names over camelBack for readability as it resembles normal text more closely. In addition it has been a well founded convention for many years to prefix proprietary/private/non-standard data/functions with an underscore, and I think private member variables fit that category perfectly. Claus

                    1 Reply Last reply
                    0
                    • R Rocky Moore

                      Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

                      Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

                      P Offline
                      P Offline
                      Phil Harding
                      wrote on last edited by
                      #41

                      Rocky Moore wrote:

                      Do you use/like the "_" to prefix private members

                      Firmly in the "m_" camp for class attributes (member variables is sooo last season) :)

                      Phil Harding.
                      myBlog [^] | mySite [^]

                      D 1 Reply Last reply
                      0
                      • R Rocky Moore

                        Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

                        Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

                        M Offline
                        M Offline
                        machowski lukasz
                        wrote on last edited by
                        #42

                        i hate prefix "_", because code is not intuitive and reading this is very uncomfortable. I'm programing in c#. Regards Łukasz

                        1 Reply Last reply
                        0
                        • N Nish Nishant

                          Rocky Moore wrote:

                          but I had hoped to never see them again. Now much of the code released by MS has private members prefixed

                          Well theoretically, you shouldn't be looking at the private members (either fields or functions), unless you are maintaining someone else's code.

                          Regards, Nish


                          Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                          Currently working on C++/CLI in Action for Manning Publications. (*Sample chapter available online*)

                          J Offline
                          J Offline
                          Jon W
                          wrote on last edited by
                          #43

                          I Like them! :rose: Why? I'm a VB.NET developer... to write none language dependent code is like coding to interfaces instead of implementations ;P What do I mean? Well to easily convert / write / use code from BOTH c# and VB.Net "_" simplifies a great bit... Mainly because vb.net is not case sensitive. I find the "_" char the least disturbing in reading / skimming through code. The m_ prefix i dislike the m_ prefix as I consider it outdated; as far as I know the m stands for member, and if I want to now a class member I take a look in the Object browser, or use the "Me" (this in c#) ex: Me._myFieldName therefore in my opinion -> m_ adds "nothing". As the previous post states, the _ is used for private members and therefore encapsulated by the class and you work with the public properties / methods instead i.o.w not that big of a problem (in my humble opinion) in contrast to language independence.

                          I S 2 Replies Last reply
                          0
                          • R Rocky Moore

                            Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

                            Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

                            D Offline
                            D Offline
                            David Veeneman
                            wrote on last edited by
                            #44

                            I hated it at first, but got used to it. I use 'm_' for member variables, and 'p_' for property variables. I still hate the underscore by itself, like '_this'.

                            David Veeneman www.veeneman.com

                            1 Reply Last reply
                            0
                            • R Rocky Moore

                              Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

                              Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

                              R Offline
                              R Offline
                              realJSOP
                              wrote on last edited by
                              #45

                              I'm not missing. I am working on a series of articles for CP since all the local roads are closed and I can't get to work. :) I only prefix compiler definitions with underscores, like so:

                              #define _USE_THIS_MSG_ WM_APP+1

                              I don't prefix variables with underscores, and don't embed variable names with underscores beyond the gratuitous "m_".

                              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                              -----
                              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                              R 1 Reply Last reply
                              0
                              • N Not Active

                                I agree, using _ is just ugly and hard to type. Unfortunatly I'm stuck at a client right now who insists on using it. Reason? Because we've always done it that way :rolleyes:


                                only two letters away from being an asset

                                A Offline
                                A Offline
                                Aaron VanWieren
                                wrote on last edited by
                                #46

                                Mark Nischalke wrote:

                                Because we've always done it that way

                                Oh no, the dreaded "We have always done it that way"!!! :-D

                                1 Reply Last reply
                                0
                                • M Mohamed Meligy

                                  I use - Pascal casing with "_" prefix for proivate members. - Pascal casing for local variables. - Camel casing for public properties, and all methods. This is meant to make reading code "easier". It's also Mirosoft naming BTW, you can find it in the class library developer guidance. Mohamed Ahmed Meligy Software Engineer SilverKey.us[^] - Egypt Branch http://GeeksWithBlogs.NET/Mohamed[^] -- modified at 0:42 Tuesday 16th January, 2007

                                  A Offline
                                  A Offline
                                  Aaron VanWieren
                                  wrote on last edited by
                                  #47

                                  Mohamed A. Meligy wrote:

                                  class library developer guidance.

                                  Just curious, but do you have a link for this. Whenever I look for this, I find a gazillion different styles being used in Microsoft example code.

                                  R 1 Reply Last reply
                                  0
                                  • R Rocky Moore

                                    Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

                                    Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

                                    N Offline
                                    N Offline
                                    neffc
                                    wrote on last edited by
                                    #48

                                    I am very agreeable with the underscore since it takes advantage of Intellisense for seeing my private/protected fields quickly. It should not matter what you name a field because it should always be accessed through a property. What I would like to hear some opinions on is the naming of User Interface controls such that I don't want my default event handlers looking really crazy i.e. do you: btnValidate buttonValidate validateButton (something else) cneff78

                                    I 1 Reply Last reply
                                    0
                                    • R Rocky Moore

                                      Well, since John Simmons got his new TV, he probably will be missing for about two days, but for the rest of you: It has been around two years I think since I have asked this question and I am curious as to if people have changed their minds. Do you use/like the "_" to prefix private members? I personal hate variables prefixed with with _underscores _as _it _can _make _reading _code() _a _pain! In the old days of Assembler and some C code, we lived with it all the time, but I had hoped to never see them again. Now much of the code released by MS has private members prefixed. So, what you think?

                                      Rocky <>< Latest Code Blog Post: SQL Server Express Warnings & Tips Latest Tech Blog Post: Microsoft doing it again!

                                      L Offline
                                      L Offline
                                      lotuspro
                                      wrote on last edited by
                                      #49

                                      I appear to be in the minority here but I *always* use the underscore to prefix private members. I do this for 2 reasons: 1.) As noted by another commentor, I consider the m_ wholly antiquated and sorely reminiscent of old school VB 2.) whenever I write a new class, especially in something like a data layer, I name my members the same as my field names in my database, but of course I have Properties also and then should also have the same name, so I end up with a simple _fieldName notation. It makes for eacy copy & paste. I'm right, that is all ;)

                                      R 1 Reply Last reply
                                      0
                                      • A Aaron VanWieren

                                        Can't stand _them. Sorry to butt in on this, but this is one thing I truly hate. Isn't this part of or all of the Hungarian notation? Which has historical roots in early programming?

                                        M Offline
                                        M Offline
                                        mc42
                                        wrote on last edited by
                                        #50

                                        No, it's not part of Hungarian notation. Hungarian notation was a programming practice that prefixed variables with the type (for example, iLoopCounter, dSalary, etc). The m_ or just plain _ prefix is a method to be able to use a good name in the class and as parameters. class myClass { string _name; public bool myFunction(string name) { _name = name; } } as an example. I think the m_ came into play when class global variables were directly accessable as it made it easier to read (nameClass.m_name is easier than nameClass._name), but with the shift to treating local variables as private and providing accessors, the m_ isn't as necessary and using the _ prefix preserves the "good" names and makes it easier to translate code between languages that are/are not case sensitive.

                                        1 Reply Last reply
                                        0
                                        • C Christian Graus

                                          avanwieren wrote:

                                          Isn't this part of or all of the Hungarian notation?

                                          No.  m_ is part of hungarian notation, but the main thing is to prefix the type as in m_hwndTheWindowHandle, m_nWindowCount.

                                          Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert

                                          E Offline
                                          E Offline
                                          eddlsda
                                          wrote on last edited by
                                          #51

                                          Both Hungarian and use of underscores have their roots in C espeically those of us that lived in a flavor of unix. Amongst the development community I worked with in the late 80s, we used underscores to avoid name collisions between file scope and local variables. We used Hungarian notation to add type and pointer details to variables especially those defined as extern. With the advent of Object-Oriented programming and the concept of encapsulation, the need to know the type essentially became less useful and besides, as those that lived through maintenance of such code, misleading or erronous. From what I have seen, the use of underscores or prefix styles is usually done to avoid name collisions between class field/member declarations and parameter names that might be used in methods or constructor parameter lists. My opinion is that there are better means to do this by either avoiding the collision or use of a qualifying this. to scope to the correct member. Hence, I do not find use of prefix or underscores useful but can live with them if used consistently.

                                          Don Eddleman Principal Enterprise Architect Healthways

                                          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