I saw lot of code (for example some Android source code) where fields name start with a m
while static fields start with s
Example (taken from Android View class source):
private SparseArray<Object> mKeyedTags;
private static int sNextAccessibilityViewId;
I was wondering what m
and s
stand for… maybe is m
mutable and s
static?
1
m
is typically for a public member (see this answer for common C code conventions Why use prefixes on member variables in C++ classes).
I’ve never seen s
before, but based on that answer:
- m for members
- c for constants/readonlys
- p for pointer (and pp for pointer to pointer)
- v for volatile
- s for static
- i for indexes and iterators
- e for events
Have you read any published standards for the project you’ve seen that code in?
One of the most famous prefix notation systems is Hungarian Notation.
There is a excellent blog post by Joel Spolsky on prefixes: Making Wrong Code Look Wrong
5
It’s called hungarian notation, and it sucks. Do some research on it, it’s actually a misunderstood concept.
It originated with a good intent, indicate variables that may cause harm, such as input directly from the user in a HTML form (be sure to strip out HTML before storing to DB for instance).
var unsafeComment = $('.input').val();
save(unsafeComment);//looks wrong
//strip out html then save
The m is for member and s for static.
5