Click here to Skip to main content
15,881,599 members
Articles / Operating Systems / Windows
Article

Programming conventions

Rate me:
Please Sign up or sign in to vote.
4.00/5 (4 votes)
25 Mar 20021 min read 157.1K   15   46
Some programming convention tables for reference

Introduction

This is less of an article, more of a reference sheet to be printed out and stuck to the wall.

Hungarian Notation

"Hungarian notation" was developed by Hungarian Charles Simonyi of Microsoft ™, hence the name. Most programmers seem to stick to a flavour they like or develop a different flavour. This is a starting point for those who wish to use it. Add extra ones in the blank rows as you see fit.

Data Type

Prefix

Example

Boolean

b

bContinue

Int

n

nIndex

Short

n

nIndex

Character

c

cFirstInitial

Float

f

Percent

Double

d

dMetres

Long

l

lCarCount

String

s

sCustomerName

Null terminated String

sz

szCustomerName

Unsigned Integer (Word)

w

wCount

Unsigned long integer (DWORD)

dw

dwAtomCount

Pointer

p

pNext

Handle

h

hWnd

Function

fn

fnReport

Class

C

CParser

Class member variable

m_

m_

Array

a

aYears

Global

g_

g_szDirectory

Windows message

Msg

msgCut

You can add some of the prefixes together where they make sense.

  • For example a member variable which is a null terminated string , "m_szName".
  • Another might be for a global integer eg. "g_nElementCount".

Windows Resources

Resource Type

Prefix

Example

Menu Item Resource

ID_

ID_EDIT_CUT

String

IDS_

IDS_STRING1

Dialog Control

IDC_

IDC_EDITBOX

ICON

IDI_

IDI_MAINICON

Cursor

IDC_CURSOR_

IDC_CURSOR_ARROW

Dialog Box

IDD_

IDD_ABOUTBOX

Accelerator

IDR_

IDR_ACCELERATOR

Bitmap

IDB_

IDC_ARROW

Free free to email me your updates/suggestions and I will update the article as necessary.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) TMR
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Avoid Hungarian Notation ! Pin
1-Apr-02 10:55
suss1-Apr-02 10:55 
GeneralRe: Avoid Hungarian Notation ! Pin
Felix Cho8-Apr-02 4:57
Felix Cho8-Apr-02 4:57 
GeneralThanks, suggestions Pin
Jim A. Johnson27-Mar-02 7:50
Jim A. Johnson27-Mar-02 7:50 
GeneralRe: Thanks, suggestions Pin
Christian Graus27-Mar-02 8:57
protectorChristian Graus27-Mar-02 8:57 
GeneralRe: Thanks, suggestions Pin
Michael P Butler27-Mar-02 9:11
Michael P Butler27-Mar-02 9:11 
GeneralRe: Thanks, suggestions Pin
Ed Gadziemski27-Mar-02 14:27
professionalEd Gadziemski27-Mar-02 14:27 
GeneralRe: Thanks, suggestions Pin
Chris Maunder27-Mar-02 22:05
cofounderChris Maunder27-Mar-02 22:05 
GeneralRe: Thanks, suggestions Pin
Jim A. Johnson28-Mar-02 6:45
Jim A. Johnson28-Mar-02 6:45 
Christian Graus wrote:
- Most important: avoid the temptation to give every data type its own prefix! When this happens the code starts to become incomprehensible because there are too many "standard prefixs" to keep track of.

Is this meant to be ironic ?


Not at all. I've seen several projects where every class has its own little prefix.. some from MS. Can't think of examples now, but in the MS case, they mostly have to do with handles: hwndMain, hbmpSomething, hpalSomething, rather than hMainWnd (or hMainWindow), hSomeBitmap, hSomePalette.

Christian Graus wrote:
FWIW, I use n for any number, so that if I need to change the type, I don't need to change it in a bajillion places.

That's where it's confusing. There are too many types of numbers - integers, floats, and bytes are all numbers. I use types in my notation specifically so that I can watch for trouble like:

cSomething = bySomething; // Why am I stuffing a byte into a char?

Kind of a contrived example, of course.. the compiler will catch the nastiest ones (comparison of signed vs. unsigned); but knowing the sizes of things halps me avoid problems.
GeneralRe: Thanks, suggestions Pin
1-Apr-02 8:37
suss1-Apr-02 8:37 
GeneralI've found an error... Pin
Gertschi26-Mar-02 22:50
Gertschi26-Mar-02 22:50 
GeneralRe: I've found an error... Pin
bryce26-Mar-02 23:32
bryce26-Mar-02 23:32 
GeneralNicely done Pin
Michael P Butler26-Mar-02 22:34
Michael P Butler26-Mar-02 22:34 
GeneralRe: Nicely done Pin
Blake Coverett27-Mar-02 0:07
Blake Coverett27-Mar-02 0:07 
GeneralRe: Nicely done Pin
Michael P Butler27-Mar-02 8:39
Michael P Butler27-Mar-02 8:39 
GeneralRe: Nicely done Pin
Lars P.Wadefalk5-Jun-08 2:01
Lars P.Wadefalk5-Jun-08 2:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.