What do you think?
-
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!
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 ;)
-
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?
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.
-
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
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
-
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!
-
Stick^ wrote:
Read a good discussion about it in Code Complete 2nd Edition.
I didn't get there yet, but yesterday I read capitol where is suggested that it might be good idea to prefix input parameters with i_, output parameters by o_ and parameters that will be modified by.... m_ ! :wtf:
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
-
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!
-
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!
-
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.
-
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!
>Do you use/like the "_" to prefix private members? My habit is to use m_ for module level variables. I never make them public. If I want to expose its value, I use a property to get or set it. I use no prefix for variables whose scope is within the method. I also use a 3 letter prefix for the data type, e.g. strName, m_lngCount, etc. It is not the only way, but it is a way I like, it is readable, and I see no reason to change. I never saw a reason to simply use a "_". I remember the days when processor cycles and memory (RAM and disk) were at such a premium that code was cryptic. Those days have been gone for decades, so I saw no reason not to use more human readable names. JD Waleska, GA
-
We call' em fields.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
-
We call' em fields.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
-
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!
-
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!
-
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!
For members: itsDoc For arguements: theDoc For locals: aOK = false; while( ! aOK ) { : : aOK = true; } return aOK;
Beware of programmers who carry screwdrivers - XTalk
-
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?
Can't stand them either. Half the time I'll fat-finger it and type ")" or "+", which means I have to stop and fix it, or look down at the keyboard to make sure my ring-finger is hitting the right key.
-
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!
No. I reject such nonsense. When you say: private int NumberOfWheels; ...that makes it pretty clear. I reject comments, prefixes, and anything besides the above to define a variable. Everything you need to know about it is in the definition. I would also avoid basing any decisions on Microsoft sample code.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles. -
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!
I am not sure what language(s) you are talking about. However, the C++ standard reserves identifiers beginning with the underscore character[17.4.3.1.2]: "Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace". Some current styles recommend using a trailing underscore instead, as in private_.
-
No. I reject such nonsense. When you say: private int NumberOfWheels; ...that makes it pretty clear. I reject comments, prefixes, and anything besides the above to define a variable. Everything you need to know about it is in the definition. I would also avoid basing any decisions on Microsoft sample code.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.It's OK with me if you reject it. I prefer my code to be readable by others. I program in VB6, VB.NET, and C#, depending on who I am programming for. The declaration of a variable is not the only place one see it. If somewhere in the code the reader comes across "NameID", I would like them to know if it is local or module level, if it is int16, int32, or int64. Chances are, someone else will have to support my code at sometime. The easier it is for them to understand it, the better off he and I are. JD Waleska, GA
-
It's OK with me if you reject it. I prefer my code to be readable by others. I program in VB6, VB.NET, and C#, depending on who I am programming for. The declaration of a variable is not the only place one see it. If somewhere in the code the reader comes across "NameID", I would like them to know if it is local or module level, if it is int16, int32, or int64. Chances are, someone else will have to support my code at sometime. The easier it is for them to understand it, the better off he and I are. JD Waleska, GA
I knew someone would mention that, but I didn't bother to head it off at the pass because I figured one would realize that with modern programming tools, that is no longer an issue. The definition of the thing is always available, and even if you're 500 lines away from it, you can always find it easily. Historically, I realize the purpose of hungarian-style notations in the variable name, but modern tools are making that notion obsolete and I prefer not to bog down my code with unnecessary stuff. Programmers coming along later won't have any confusion no matter what notations they are familiar with. If they can't read the variable definition, then they probably shouldn't be writing code in the first place.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles. -
I knew someone would mention that, but I didn't bother to head it off at the pass because I figured one would realize that with modern programming tools, that is no longer an issue. The definition of the thing is always available, and even if you're 500 lines away from it, you can always find it easily. Historically, I realize the purpose of hungarian-style notations in the variable name, but modern tools are making that notion obsolete and I prefer not to bog down my code with unnecessary stuff. Programmers coming along later won't have any confusion no matter what notations they are familiar with. If they can't read the variable definition, then they probably shouldn't be writing code in the first place.
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.Sorry, but I don't take such an elitist view. I am all for new programmers learning, and code excerpts may not always be in the IDE. In addition, code tends to live a long time. You can't always count on the IDE being effective. Look at how MS screwed up the IDE from VB6 to VB.NET. After over 6 years of working with .NET, the IDE is starting to get back to being as useful as it was in 1998. I think how you notate your variables is perfectly fine. I choose to do mine the way I do for specific reasons. I am not likely to change just because Microsoft says so. JD Waleska, GA