PDA

View Full Version : Hungarian notation


Nikos
01-09-2004, 05:34 PM
Hi everyone,

I have been lately exploring the Win32 API in C and have been using Hungarian notation for all my variables but they are really starting to clutter up my code, these silly prefixes.
e.g. lpszString (long pointer to zero terminated string) bla, bla.

So I'm just interested to see what kind of naming convention everyone else uses for their projects. I know its best to use just one and stick to it throughout the project, but I'm still just a beginner and have yet to discover a method that would suit me better so that I can get myself a bit more organised. :blush:

thanks

dead_eye
01-10-2004, 06:21 AM
For my own classes I don't know what the style is called, but I call it STL style. Everything lower case, no capital letters, no prefixes, _ between words, macros and constants (sometimes) fully capitalized, prefer size_t to unsigned or UINT, something like this:

// Lightwave ID Tags
#define LW_TAG_FORM 1297239878ul
#define LW_TAG_LWO2 844060492ul
#define LW_TAG_LAYR 1381581132ul
#define LW_TAG_PNTS 1398034000ul
#define LW_TAG_POLS 1397509968ul
#define LW_TAG_FACE 1162035526ul

// Lightwave Data Types
typedef signed char lw_int1;
typedef signed short lw_int2;
typedef long lw_int4;
typedef unsigned char lw_uint1;
typedef unsigned short lw_uint2;
typedef unsigned long lw_uint4;
typedef float lw_float;
typedef string lw_string;

// Lightwave Structures
struct lw_tag {
union { char name[4]; lw_uint4 value; };
};

struct lw_chunk {
lw_tag tag;
lw_uint4 size;
};

struct lw_subchunk {
lw_tag tag;
lw_uint2 size;
};

struct lw_vector {
lw_float x;
lw_float y;
lw_float z;
};

struct lw_vertex_attr {
lw_uint2 n_vertex : 10;
lw_uint2 flags : 6;
};

bool lw_parser::loop_chunks(void)
{
// loop chunks
for(;;)
{
// read next chunk
lw_chunk chunk;
if(!file.read((char*)&chunk, sizeof(lw_chunk))) break;

// forward to processing functions
switch(chunk.tag.value) {
// new layer
case(LW_TAG_LAYR) : {
if(!on_layr()) return false;
break;
}
// point list
case(LW_TAG_PNTS) : {
if(!on_pnts()) return false;
break;
}
// polygon list
case(LW_TAG_POLS) : {
if(!on_pols()) return false;
break;
}
// ignore chunk
default : {
reverse_byte_order(chunk.size);
if(chunk.size % 2) chunk.size++;
file.offset(chunk.size);
}
}
}

return true;
}

Only when creating custom MFC control classes or using DirectX will I ever break from this. But if you're learning the Win32 API, keep your GUI code similar to that of the API. For example, if you're creating your own custom tab common-control, your functions should be notated just like the Win32 API. But if you're writing your own algorithms, classes, engine or whatever, pick a style and stick with it.

CGTalk Moderation
01-17-2006, 03:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.