![]() |
|
#1
|
|||
|
|||
Style Guide Books??I've found a few web documents that discuss naming and style conventions for C++, but are there any somewhat definitive books on the subject that any of you recommend?
There are so many style ?'s floating though my head? Should I start a class name w/ "C" or "T" or something else. Should I prefix variables w/ the data type, e.g. iWeight for an integer variable used for weight values. Should I intial capitalize my own function names? How about member funciton names? ... the list just goes on and on. Any direction on C++ naming and style conventions and practices would be MUCH APPRECIATED. THANKS! |
|||
|
#2
|
||||
|
||||
|
Quote:
Hello. Welcome to GIDForums. This is a topic that has come up several times around here and I would bet that you would get a different opinion from everyone that posts here. I can tell from the code I see posted here that we all differ somewhat in our naming conventions. What you need to decide is what works best for you but stays within some general bounds. Your code needs to be readable, not only by you but also others. As for the type before the variable name? (I can't remember what this is called - I think it is named after somebody.) I am not a big fan of that myself. In your example, what if your program was expanding to allow a floating point for the variable weight? You have two choices, leave it as iWeight which makes matters worse or change your entire code to the variable name fWeight. So I think that there are some definite downsides to that. I will provide several links of posts by other members as well as myself that make some good points about style
I am not sure if this helps or not. If you are a professional programmer working for someone else, you may not have a whole lot of choice in some of these matters. If you are fortunate enough to be a free lancer or hobbyist, you can make your own style that fits you best. You need to pick a style that makes the most sense to you, while trying to keep your program world-readable. Look through some of the code that is posted here and try to see what is the most readable to your eyes. If you have any more links or comments that you think are rather good, I would be interested in hearing about them. Cheers, d |
|
#3
|
||||
|
||||
|
Quote:
I can't remember the name either of the prefix -- it always reminded me of an animal like hippo- something, but I digress. Using the prefix can be very useful in certain situations. In VB I use it all the time got the control and features (forms, boxes, labels, etc) but rarely for variables. MFC and the M$ API use them all the time and are quite handy there also. So when you interface with large systems like MFC, Oracle, and the like, it's extremely useful to have that style of definition. For most programs though it's sometimes overkill. But again if you are writing an extremely complex and large program/system, they may stop many headaches. It will allow you to use the 'same' variable name in different code sections without fear of mixing them up. But as to dsmith's allegation about changing iWeight to fWeight, that's pretty mich a non-issue with today's editors and IDEs IMHO. As I mentioned in the tutorial -- or maybe I didn't -- my style is: Variables
But methods are just functions so they follow the upper/lower style. Develop your style -- sometimes it takes years to fall into a pattern. I know I've changed my style many times over the years. __________________
Definition: Politics Latin, from poly meaning many and tics meaning blood sucking parasites -- Tom Smothers |
|
#4
|
||||
|
||||
|
Quote:
Very true. Hell, even notepad has a Search/Replace function. But it does take discipline (of which I have none). So in some (most?) cases these variable names would not be changed and add to the confusion. See, what I mean about a million styles? Walt and I have pretty similar coding styles and we still can't agree. ![]() |
|
#5
|
|||
|
|||
|
Thanks a lot guys!
|
Recent GIDBlog
Compress Your Web Site by gidnetwork
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| complete e-marketing guide | primelibra | Search Engine Optimization Forum | 4 | 01-Aug-2004 20:45 |
| IRC Services Admin help guide | Allowee | Open Discussion Forum | 2 | 25-Apr-2004 08:32 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
| C++ books for newbie | mak90thug | C++ Forum | 4 | 04-Feb-2004 14:58 |
| Video Card FAQ & Overclocking Guide (Updated) | asanthadenz | Computer Hardware Forum | 2 | 05-Mar-2003 18:37 |
Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The