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, ...

  1. #1
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42

    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

    what do you guys say?
    C Rulz!

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    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:

    strMyName CString Data type
    pcMyName pointer to char data type
    m_nCmdShow member integer variable of a Class
    nAge Integer Data type
    szMyName A null terminated string
    CEdit A Class definition

    Hope this helps! Good luck!

  3. #3
    Registered User steve_i83's Avatar
    Join Date
    Aug 2001
    Posts
    42
    thxs alot ... i found this site which talks about its good and bad points and has some links to other usefull info
    http://ootips.org/hungarian-notation.html

    at last i shall program clean easy to read code ...
    C Rulz!

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    Glad I could be of help!

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    I personally find hungarian notation to be redundant. I prefer another popular style, which is like this:

    class MyClass{
    int myVariable;
    int MyFunction();
    };

    MyClass myObject;

    Here, every word/secxtion of the name except the first is always in caps, and the first is in caps if it is a function or class, lowercase if it's a variable or object.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    15
    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.

  7. #7
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    I personally find hungarian notation to be redundant.
    I HATE HUNGARIAN NOTATION!!

    It's like every variable name has some nasty appendage sticking out of it.

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    32
    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.
    cerion
    Use the code Luke.

  9. #9
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    nick:
    I HATE HUNGARIAN NOTATION!!
    cerion: I personally prefer to use no notations at all.
    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 .
    Last edited by Carlos; 10-03-2001 at 03:23 AM.

  10. #10
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    steve_i83 :
    What a pitty, the "More info" links are dead
    (http://ootips.org/hungarian-notation.html).

    I was trying to read Charles Simonyi's article...

  11. #11
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    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)

    Is it possible to mixup hungarian notation?
    http://www.stanford.edu/class/cs193d/rsrc/stlweb.html

    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.

  12. #12
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    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.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  13. #13
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Personally, I find hungarian notation good ONLY for code that uses a lot of global variables. But for most purposes it is a good idea to just give variables names of what they do. For example:
    Code:
       bool MouseClicked = false;
       int NumberOfClicks = 0;
       char FirstLetter = 'h';
       //and so on...
    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.

  14. #14
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    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 .

    Btw. my style is a mixture of styles, regarding notation, source code formatting (kinda bestof ).

    After years of professional programming (8 hours/day) everybody will acquire a specific style.

    It's like hand-writing. When you're no more a teenager, you probably have your specific style, but, if it's too weird, nobody will understand you. That's my point.

    Style is important, just don't be excentric. At least not if you're a programmer, working in a team...

  15. #15
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  2. Good resources for maths and electronics
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 12-22-2004, 03:23 PM
  3. Good C++ books for a begginer
    By Rare177 in forum C++ Programming
    Replies: 13
    Last Post: 06-22-2004, 04:30 PM
  4. what is good for gaphics in dos
    By datainjector in forum Game Programming
    Replies: 2
    Last Post: 07-15-2002, 03:48 PM
  5. i need links to good windows tuts...
    By Jackmar in forum Windows Programming
    Replies: 3
    Last Post: 05-18-2002, 11:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21