« Home « Coding Conventions

Conventions for Use of Hungarian Notation

The following practices are used for identifier names throughout the library, and also the various Android app projects from this organization. Note that, in many cases, in which only one object of a given type appears in a block of code, the prefix just is the variable identifier. Otherwise, the prefix appears as part of some innerCamelCase identifier that includes a semantic name for the variable.

Simple Values

These identifiers are related to variables containing simple values — primitives, or the wrappers for those primitives.

Prefix Meaning Actual Types Examples
b A Boolean entity — either true or false. Could refer either to a primitive boolean or a Boolean wrapper object.
  • boolean
  • Boolean
  • bEnabled
  • bDone
  • bConnected
c Any single character.
  • char
  • Character
  • cCommand
mask Any int or long that is being used as a bitmask, rather than as a numeric value. This prefix is a reminder that the integer primitive should not be used as a number.
  • int
  • Integer
  • long
  • Long
  • maskFlags
n An unsigned integer — that is, a number which is expected to be ≥ zero. The letter choice refers to the mathematical notation ℕ for the set of natural numbers. Since Java does not include built-in enforcement of signed vs. unsigned integers, this prefix is used to remind a human developer that the value is expected to be always greater than or equal to zero. Further, it is common to use negative values in these variables in order to track error conditions or other special circumstances, such as setting -1 to mean "not yet initialized".
  • int
  • Integer
  • long
  • Long
  • short
  • Short
  • nCount
  • nSeconds
r A floating-point decimal number of any precision. The letter choice refers to the mathematical notation ℝ for the set of real numbers.
  • float
  • Float
  • double
  • Double
  • rLazyPi
  • rEasyE
res The integer constant referring to an Android resource ID. While the underlying data type is always int, it is generally useful to denote any integer entity that is known to carry a resource identifier.
  • int
  • resScreenTitle
  • resButtonImage
  • resLayout
s A simple string.
  • String
  • sUUID
  • sName
ts A long integer value which holds a Unix timestamp. This value will typically be obtained from a Date or Calendar instance, or from some Android OS function which give time values as a long integer of milliseconds.
  • long
  • tsCutoff
  • tsNow
y A byte. This letter choice was forced because b already stands for "Boolean". Usually used only as part of an array of bytes while processing raw binary data, e.g. ayBlob.
  • byte
  • Byte
  • yRaw
z A signed integer — that is, a whole number which might be less than, equal to, or greater than zero. The letter choice refers to the mathematical notation ℤ for the set of all integers. Since Java does not include built-in enforcement of signed vs. unsigned integers, this prefix is used to remind a human developer that this value is expected to range across the entire integer set, in contrast to the n prefix above.
  • int
  • Integer
  • long
  • Long
  • short
  • Short
  • zErrorCode
  • zTemperature

Specific Java or Android Object Types

The prefix o is used for any nondescript Java object, but using this for every non-primitive identifier would be pointless. Thus, several Java classes, Android classes, and other "types" or objects get their own specific notational prefixes.

Prefix Meaning Actual Types Examples
act Any activity instance.
  • Activity
  • AppCompatActivity
  • act
  • actParent
bind A Binder to a Service. Typically, this prefix just is the identifier, since a function will generally not refer to more than one Binder at a time.
  • Binder and its descendants.
  • bind
btn A Button appearing in the UI.
  • Button and its descendants.
  • btnSave
  • btnCancel
cfg Any instance of the Android OS Configuration class, or an instance of any other class that represents some sort of "configuration" in abstract.
  • cfg
cls A Class instance. Classes are frequently passed around as hints to generic/template parameters, or used by any feature that depends on Java reflection.
  • Class
  • clsType
  • clsNodes
conn Any object that represents an open connection to something, like a database or a Service.
  • conn
crs A Cursor on a database result set.
  • Cursor
  • crs
  • crsResults
ctor A constructor discovered via Java reflection.
  • Constructor
  • ctor
ctx A Context.
  • Context
  • ctx
  • ctxApp
db An instance of a database, such as a SQLiteDatabase.
  • SQLiteDatabase
  • db
dbh A database "helper" class, which provides access to a database, such as any descendant of SQLiteOpenHelper. This is the class which typically serves as the API between the database connection and the rest of the app.
  • dbh
dia Any instance of a dialog in the UI.
  • any dialog object
  • diaConfirm
fld A Field discovered via Java reflection.
  • Field
  • fldName
filter An IntentFilter (for a receiver).
  • IntentFilter and its descendants.
  • filter
frag A Fragment.
  • Fragment and its descendants.
  • fragStatusLog
  • fragItemList
  • fragButtonBar
hndl A Handler implementation.
  • Handler and its descendants.
  • hndlCollection
  • hndlBroadcasts
infl Any Android UI "inflater".
  • LayoutInflater
  • MenuInflater
  • infl
  • inflMenu
info Any of several Android standard classes that represents or contains a discrete structure of information provided by an Android OS service or sensor.
  • CellInfo
  • DhcpInfo
  • PackageInfo
  • SQLiteColumnInfo
  • WifiInfo
  • any other similar "informational" data structure
  • info
  • infoCell
  • infoDHCP
json A JSON object, usually produced by Gson.
  • Any JSON object representation.
  • jsonData
  • jsonResponse
l An instance of a listener. These are generally referenced within the localized context of a method, and thus often have no semantic name following the prefix. The type of "listener" is dependent on the object that provides it.
  • any object that is used as a "listener"
  • l
lay A Layout for the app's user interface.
  • Layout and its descendants
  • layMain
  • layButtonBar
lens (library-specific) Any instance of a class which implements Refractor and/or extends Lens as part of the SQLiteHouse feature.
  • lens
loc Any object representing a location or locale.
  • Location (GPS)
  • CellLocation (mobile telephony)
  • any other representation of a location
  • Locale
  • locGPS
  • locCell
  • locHere
map Any Map, such as a HashMap
  • Map and its descendants
  • mapNames
  • mapRefractors
mgr Any of the various Android classes that is a "manager" of some system component. If the context of the manager is obvious from the method, or there is exactly one manager in scope, then the identifier might not have a semantic name, but typically the name will also indicate which manager has been obtained.
  • Any instance of a "manager" class.
  • mgr
  • mgrBluetooth
  • mgrTelephony
menu A Menu in an app UI.
  • Menu
  • menu
mi A MenuItem in an app UI.
  • MenuItem
  • miSettings
  • miTweet
mth A Method discovered by Java reflection.
  • Method
  • mthSetName
pcl A Parcel.
  • Parcel
  • pcl
prefs A reference to the application's preferences, or any object which can be used as an API to access those preferences.
  • prefs
proc Any class to which the app's logic for processing data is confined. Typically, such a "processor" class would be bound to a Service and a BroadcastReceiver, both of which would feed incoming signals (such as Intents) into the processor via its public methods.
  • any class used as a "processor"
  • proc
qctx (library-specific) (deprecated) A QueryContext instance, describing the context of a SQLite query in progress, as part of the SQLiteHouse feature.
  • qctx
rcv A BroadcastReceiver.
  • BroadcastReceiver and its descendants
  • rcv
  • rcvSignals
  • rcvData
rng Any instance of Random. The prefix choice here reflects the most common use of the class, which is as a random number generator. Typically, this will be declared as a static constant to be used by the class that needs it, and will thus appear as RNG instead.
  • Random
  • RNG
sb Any StringBuffer or StringBuilder instance used to accumulate a string value.
  • StringBuffer
  • StringBuilder
  • sb
  • sbMessage
sched Any class that is used to schedule tasks to be executed at certain times or intervals.
  • any class used as a scheduler
  • sched
sig An Intent — that is, a signal received by the current context.
  • Intent
  • sig
  • sigAction
  • sigInbound
  • sigOutbound
spin A Spinner control in the app UI.
  • Spinner and its descendants
  • spinFrequency
srv A Service instance.
  • Service and its descendants
  • srv
task Any class representing a task to be run on a separate thread.
  • Runnable implementations
  • TimerTask descendants
  • AsyncTask descendants
  • taskConnect
  • taskBroadcast
timer A Timer.
  • Timer and its descendants.
  • timer
uri Any object representing or containing a URI.
  • Uri
  • uri
vals A ContentValues instance.
  • ContentValues
  • vals
  • valsToInsert
w Any View. Additional crumbs might be appended to the prefix to indicate a view type, such as tw for TextView.
  • View and its descendants
  • wClicked
  • wSelected
  • twTitleCard
x Any Exception.
  • Exception and its descendants
  • x
  • xNull
  • xAccess

Meta-Prefixes

These are related to a class member's role within its class, and are prepended before any other prefixes related to type or usage.

Prefix Meaning Examples
m_ The entity is a member of a class instance. The prefix could be read by a human as "my" and alleviates the need to use the this keyword to disambiguate the member from a local variable with a similar name.
  • m_sObjectName
  • m_bEnabled
s_ The entity is a static member of the class. Note that static constants do not generally carry this prefix; they are named with ALL_CAPS_WITH_UNDERSCORE_SPACES instead.
  • s_oSingletonThing
  • s_nPersistentCount

Collections

Similar to a meta-prefix, these prefixes denote collections of entities, and are prepended before any of the other notational characters in the identifier name.

Prefix Meaning Actual Types Examples
a Any array, list, or other similar linear collection.
  • any literal array
  • List and its subclasses
  • any other Collection descendant
  • any other Iterable implementation
  • asNames
  • anJerseys
  • aoListeners
v A Vector. Vectors are special, and worth distinguishing from other collections, for their thread-safety, and the specific functions provided by that class.
  • Vector
  • vsKeys
  • voSensorLogs