J
Juha Nieminen
Nick Keighley said:guk! And this leads to the hungarian madness!
How does using the 'm' prefix (as opposed to the '_' prefix) "lead to
hungarian madness"?
Nick Keighley said:guk! And this leads to the hungarian madness!
How does using the 'm' prefix (as opposed to the '_' prefix) "lead to
hungarian madness"?
Bo Persson said:It's technically allowed, but perhaps not "fine".
Seeing a leading underscore would make me think "implementation
specific name in the global namespace". Isn't that adding to the
confusion, rather than reducing it?
I use the following:
sFoo // for static variables
iFoo // for member variables, "i" stands for "instance"
aFoo // for function arguments
foo // local variables have no prefix
On 12/30/10 08:42 PM, Nick Keighley wrote:
....
That example is the classic case where you don't!
The ambiguity arises when you use the member variable in the constructor
body.
Which books? It used to be prevelant, but I've not seen it in
a long time.
Taligent used fMemberName -- I think the f was short for field.
In another recent thread on this topic someone suggested
not putting "warts" on member names but on local variables
since their scope is more limited.
This goes against another rule I've heard: the length of
a variable name should be inversely proportional to its scope.
I regularly use names like i and j for loop indexes (and I'd
definitely not want to prefex them), but no where else.
You are trolling. The number of characters in a variable name is an
irrelevant metric; what is important is to have a meaningful variable
name which has nothing to do with the number of characters modulo any
coding standard requirement to have a prefix.
A compiler may impose an upper limit on symbol name length.
I use the following:
sFoo   // for static variables
iFoo   // for member variables, "i" stands for "instance"
aFoo   // for function arguments
foo   // local variables have no prefix
so a constructor for example looks like this:
foo::foo(int aWibble) : iWibble(aWibble) {}
It works quite well (I picked up from when I was a Symbian OS programmer)..
Yet another bullshit rule Mr Kanze.
Just because "i" is acceptable as a
local variable name (for loop index) does not suddenly make the
generalization that "variable name should be inversely proportional to
its scope" valid.
struct point
{
int x;
int y;
};
You are trolling.
The number of characters in a variable name is an
irrelevant metric; what is important is to have a meaningful variable
name which has nothing to do with the number of characters modulo any
coding standard requirement to have a prefix.
A compiler may impose an upper limit on symbol name length.
Opposed to underscore suffix. Nothing leads to madness. Usually the
discussions of code style conventions ... just turn into such
emotional "ugly", "confusing", "mad", etc. madness. In practice worst
is lack of consistency. So when gathering team then it is best to
argue, vote and write it down as policy. Whatever strange it is ... if
used consistently the code base feels more uniform.
no he's making a technical point with which you disagree.
I don't agree. I don't think its a one-to-one mapping but longer names
do get to be a pain and short names invite name space collisions.
One
uses named scopes such as classes or namespaces to avoid "name space
collisions".
Sounds like a shit compiler especially if it didn't warn about truncation..
On Dec 31, 2:54 am, James Kanze <[email protected]> wrote:
Jeff Schwab and others have suggested using ii and jj rather
than just i and j. I think that's partly to make variables
easier to pick up. Adding a one character prefix to a one or
two character variable gives a length of two or three. I'm
just trying it out at this point.
Do any impose upper limits for variable lengths?
Nick Keighley said:"using different letters for different types of variables" sounds
excatly like an invitation to hungarian. I've just been introduced to
a large hungarian code base and I'm not enjoying the experience.
Juha Nieminen said:It's not out of the realm of possibility that you are simply being
prejudiced and not even trying to actually use the naming convention
used in that code to your advantage (ie. to help you read the code
more easily).
The problem with a trailing underscore is that it makes code visually
more confusing (especially when the underscore is followed by other
symbols such as dots or dashes). Using a letter prefix is less confusing
(and also gives more possibilities, ie. using different letters for
different types of variables).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.