Click here to Skip to main content
15,891,513 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.3K   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

 
Questionn is for integer? Pin
Felix Cho8-Apr-02 4:59
Felix Cho8-Apr-02 4:59 
GeneralAvoid Hungarian Notation ! Pin
Warren Stevens28-Mar-02 3:11
Warren Stevens28-Mar-02 3:11 
GeneralRe: Avoid Hungarian Notation ! Pin
Nish Nishant28-Mar-02 3:22
sitebuilderNish Nishant28-Mar-02 3:22 
GeneralRe: Avoid Hungarian Notation ! Pin
Warren Stevens28-Mar-02 3:52
Warren Stevens28-Mar-02 3:52 
GeneralRe: Avoid Hungarian Notation ! Pin
Kevin McFarlane28-Mar-02 7:55
Kevin McFarlane28-Mar-02 7:55 
GeneralRe: Avoid Hungarian Notation ! Pin
Jason Gerard28-Mar-02 10:14
Jason Gerard28-Mar-02 10:14 
GeneralRe: Avoid Hungarian Notation ! Pin
Alvaro Mendez28-Mar-02 12:02
Alvaro Mendez28-Mar-02 12:02 
GeneralRe: Avoid Hungarian Notation ! Pin
Rick York30-Mar-02 13:16
mveRick York30-Mar-02 13:16 
GeneralRe: Avoid Hungarian Notation ! Pin
Tim Smith28-Mar-02 5:46
Tim Smith28-Mar-02 5:46 
GeneralRe: Avoid Hungarian Notation ! Pin
Warren Stevens28-Mar-02 6:49
Warren Stevens28-Mar-02 6:49 
GeneralRe: Avoid Hungarian Notation ! Pin
Tim Smith28-Mar-02 5:51
Tim Smith28-Mar-02 5:51 
GeneralRe: Avoid Hungarian Notation ! Pin
Warren Stevens28-Mar-02 6:51
Warren Stevens28-Mar-02 6:51 
GeneralRe: Avoid Hungarian Notation ! Pin
Tim Smith28-Mar-02 8:01
Tim Smith28-Mar-02 8:01 
GeneralRe: Avoid Hungarian Notation ! Pin
Roger Allen28-Mar-02 6:17
Roger Allen28-Mar-02 6:17 
In some defence of hungarian notation. I use a variant of it myself, so in reply to your points:

Warren Stevens wrote:
Hungarian notation was invented a LONG time ago for people that didn't have the great IDEs and compilers we have today
So was C/C++ (in the scheme of things), Just because something is old doens't mean its dead in the water.

Warren Stevens wrote:
Some times it's better not to include type information in your names. If the type changes, the names get misleading
When this happens, I use find and replace, that what great IDE's are for isn't it?

Warren Stevens wrote:
LPCTSTR - the "L" stands for "long" as in long pointer - But there are no long pointers anymore!

WPARAM - has changed size, but the name is still old.

OK, theres not much I can say about these, they are a carry over from 16-bit windows, and I think M$ would have done away with them if they could.


Warren Stevens wrote:
If you name your variables like this, you'll just end up in the same trap.
Once again, I think Find/Replace can come to the rescue.


I do beleive I read the orignal artical a long time ago. The code you quote is a bad example of how not to write code I think.

Hungarian notation can be a good thing. I think it just comes down to personal preference. Like I said earlier I use a variant of it, but its not a religion.




Roger Allen
Sonork 100.10016

If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
GeneralRe: Avoid Hungarian Notation ! Pin
Warren Stevens28-Mar-02 6:44
Warren Stevens28-Mar-02 6:44 
GeneralRe: Avoid Hungarian Notation ! Pin
Jim A. Johnson29-Mar-02 17:53
Jim A. Johnson29-Mar-02 17:53 
GeneralRe: Avoid Hungarian Notation ! Pin
Warren Stevens1-Apr-02 3:32
Warren Stevens1-Apr-02 3:32 
GeneralRe: Avoid Hungarian Notation ! Pin
yarp28-Mar-02 7:39
yarp28-Mar-02 7:39 
GeneralRe: Avoid Hungarian Notation ! Pin
Bill Leibold28-Mar-02 11:41
Bill Leibold28-Mar-02 11:41 
GeneralRe: Avoid Hungarian Notation ! Pin
29-Mar-02 0:35
suss29-Mar-02 0:35 
GeneralRe: Avoid Hungarian Notation ! Pin
Christian Graus28-Mar-02 12:05
protectorChristian Graus28-Mar-02 12:05 
GeneralRe: Avoid Hungarian Notation ! Pin
Shog929-Mar-02 19:08
sitebuilderShog929-Mar-02 19:08 
GeneralRe: Avoid Hungarian Notation ! Pin
Warren Stevens1-Apr-02 4:13
Warren Stevens1-Apr-02 4:13 
GeneralRe: Avoid Hungarian Notation ! Pin
Christian Graus1-Apr-02 9:23
protectorChristian Graus1-Apr-02 9:23 
GeneralRe: Avoid Hungarian Notation ! Pin
Andy Smith1-Apr-02 10:17
Andy Smith1-Apr-02 10:17 

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.