Good Programming Style for Win32

This is a discussion on Good Programming Style for Win32 within the Windows Programming forums, part of the Platform Specific Boards category; I have been programming for some time but have not yet picked up one certain style and i want to, ...

Good Programming Style for Win32

I have been programming for some time but have not yet picked up one certain style and i want to, but i need to make an informed decision...
i think its probably good to use a mixture of caps and small to define variable names eg MyString
ive heard its also a common idea to use lowercasse letters in the front of a variable name to define its type eg ...
char cMyChar
int iMyInt
class *clpMyClassPointer

Using notation to identify objects is a good idea. Especially if others have to maintain your work. The mix case variable is good ( ex. MyName). As for the variable prefix, I would stick to the Hungarian Notation. It is very commmon and most programmers will know it.

There are lots of web sites out there that can give you all of the prefixes. Here are a few:

I have seen that Style before, mainly in VB programs. There is certainly nothing wrong with that naming convention. I prefer a style that allows me to look at an object and determine what that object contains, without having to go look at the declaration statement. MSVC++ makes looking at variable declarations very easy (just a right click away), but I am lazy and that is one less mouse click that I have to do.

I have worked on programs with 100's of thousands of lines of code, that were maintained by a dozen or so programmers. The Hungarian Notation style has saved me thousands of right mouse clicks.

I personally prefer to use no notations at all. I just make sure that people will know what the variable is for when they see it. Like for example if I am doing a program which needs output two words, "Hello" and "World" I would have something like this...

int main()
{

char HelloString[] = "Hello";
char WorldString[] = "World";

printf("%s %s\n", HelloString, WorldString);

}

Well okay I've never had anything THAT stupid in my naming schemes but I'm sure you can get the picture. If people want to know if it's a string or int or float or double or whatever they can either click away to find out (as DrCodeGuru dislikes) or they can try printing the variables out and figure out what type it is by trying different %s, %c, %d, etc. or they can just scroll up and look at it's declaration hehe. Most of the time no one looks at my code anyways so I've had no reason to make it easier on someone else.

Well, guys, as long as you're "developing" your homework only, and your source code is less then 100 lines , well, don't use any notation.
But try to work like this in a team, with a more thousand lines source, you'll see, why it's worth to use e.g. hungarian notation ar a derivate of it.

Actually, we use a special hungarian notation, differentiating global and non-global vars, flags, pointers, in and out parameters (allthese in any mixture ), using sufixes and prefixes, which makes the code readable and bug-free. Since I use this coding-style in my own projects, my life is also much easier!

Every professional programmer has to use a kind of notation. Sometimes, there are also constraints regarding the coding style. Especially bigger software-companies have their own "Programming guideline". If you work for them, you *have to* use the adequate style and/or notation.

C'est la vie!

Btw, Charles Simonyi, who invented the hungarian-notation was a smart guy, *even* if he worked at Micro$oft .

Well I've gotten past 1000 but I'm not in the 10,000 LOC range yet.
I don't really have time to write a large program like that myself.

For c++, I do have a naming convention
4 space tabs (converted to spaces)
all variables lower case
#defines are all caps
All types and aliases start with caps
{} are in k&r notation
I use underscores not mix case (this as the advantage that I can spell check the source, though I've been meaning to adding some common c functions to the list)

Notice the string szName, that seems funny, I don't recall string objects being null
terminated. It's not really the author's fault. For large project, I would imagine
writing a lint type program to check hungarian correctness.

I'm in the n,000,000 LOC range, and the only Hungarian convention I use is a lower case "p" in front of pointers.

This type of thing may have had a use once, but todays IDE's make it redundent. If I am not sure what type a variable is, I put my cursor on it, and the IDE tells me, offers to take me to the declaration, and shows me it's current value.

It would be hard to get confused by what those variables do (assuming they are used for what the name says). One thing I suggest to all people who are new to programming or even the old programmers who are just sloppy and lazy is to find a style you like and stick with it! Don't use my technique then start using hungarian notation in a different class.

master5001 :
One thing I suggest to all people who are new to programming or even the old programmers who are just sloppy and lazy is to find a style you like and stick with it!

As I've written, style can be sometimes project-dependant
If the company expects a specific style from you, the developer, you have to do it that way, or you'll get some trouble. I know it from my own experience .

Well said Carlos. Many will just begin to have a style as time goes on. As for the mixture of styles I stand firm on my saying don't switch around styles too much. I admit that I do that from time to time. Global variables are really painful for teams of programmers. Any variation of the hungarian notation helps sort out globals. But nonetheless, good ol' comments can't be beaten when trying to express what a variable does, who can argue that.