Naming Conventions – Field Naming Convention: Starting with ‘m’ or ‘s’

coding-standardsnamingprogramming practices

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?

Best Answer

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

Related Topic