An interesting detail about variable name
Asked Answered
P

3

5

I have read tutorials all over the web with different kinds of tutorials specified on game (however, this turns out to be pretty general).

Are there any reasons to why many developers name their variables like:

mContext

For me it is default to just name it "context" or something similar.

Are there any reasons why the "m" are before? (I know that this is a matter of style, but I'm just curious what it stands for)

Pederson answered 2/9, 2010 at 16:30 Comment(2)
This isn't Hungarian notation, as others have mentioned. But the Android coding guidelines (for contributions to Android core) says that code should follow this style (m for member variables, s for statics etc.).Underlet
Can you elaborate, in what way this is not a Hungarian notation ? I known, that this is in coding guidelines, but I see no reason to use this ... For me, it is confusing, when I read the sources.Pinfeather
F
5

The m will be to signify that the object is a member variable of the class in question. It's a common use of Hungarian Notation to prefix the name with clues to the variable's purpose or type.

Forbis answered 2/9, 2010 at 16:36 Comment(1)
I usually associate Hungarian Notation with type prefixes, e.g. "czName" for a zero-terminated array of characters. I find this use annoying. Prefixes for scope ('g' for global, 'm' for member) make it easy to differentiate between locals and non-locals without having to hunt for declarations. Modern IDEs make this less important (until you have to read the code in printed-out form).Mohamedmohammad
P
8

To those of us who disapprove of cluttering up our variable names with such characters, they're known as "warts". In my opinion, with today's IDEs it is better to leave the warts off, because we can readily distinguish between local variables and member variables without their help.

Poindexter answered 2/9, 2010 at 16:41 Comment(2)
Thank you too! This is my opinion too.Pederson
Exactly, same opinion here.Pinfeather
F
5

The m will be to signify that the object is a member variable of the class in question. It's a common use of Hungarian Notation to prefix the name with clues to the variable's purpose or type.

Forbis answered 2/9, 2010 at 16:36 Comment(1)
I usually associate Hungarian Notation with type prefixes, e.g. "czName" for a zero-terminated array of characters. I find this use annoying. Prefixes for scope ('g' for global, 'm' for member) make it easy to differentiate between locals and non-locals without having to hunt for declarations. Modern IDEs make this less important (until you have to read the code in printed-out form).Mohamedmohammad
H
2

Many programmers like to prefix their variables with lowercase letters that represent the object type that variable represents. For example:

var strMyString = new String();

Hogfish answered 2/9, 2010 at 16:38 Comment(1)
Thank you, but DoctorRuss was quicker. :)Pederson

© 2022 - 2024 — McMap. All rights reserved.