   C++ Coding Conventions
  Hi all in the ''For Beginners'' forum.After a brief and rather half hearted attempt at learning to code, I''ve stumbled upon GameDev.net and my coding loins are beggining to stir once more. I''ve decided to really work hard with it and not be so disallusioned with all the DOS work.Anyways, before I leave the forum for today and crack open my C++ book of choice I wondered if I could throw a question at the more experienced coders here regarding coding conventions.Most C++ books I''ve looked through are fine in terms of introducing someone to C++ in terms of the syntax, but teach little, if anything about the style.I only ask so that I can instill some good habits now while I''m taking my first steps into C++ and not later, when bad habits will surely be more difficult to remove.So, what are your tips in terms of header style, class names, variable names, use of the tab key to space blocks of code, etc?Oh, and wish me luck, heh heh! 
quote:my coding loins are beggining to stir once more.Oh man, I SO did not need to know that.The thing I would worry about most is actually not the style in which you format your code, but the style in which you write your code -- e.g., avoiding the misuse and/or misunderstanding of certain language concepts.But, to answer your question, its a matter of personal preference and the readability of your code. While you may not be working with other people now, at some point you probably will, and if they can''t stand to look at your code because its formatted awfully, that will be a problem.My personal preference is to avoid complex variable prefixing, except for g for global and m for class member. And I use Doxygen (www.doxygen.org) in my comments.It''s really going to boil down to what you find readable, though; this is a very religious topic. Once you get some kind of demo or have a problem with your code and post it here or someplace else, people will usually tell you if your style is so cramped as to make your stuff unreadable. I wouldn''t worry too much about it though.quote:at the more experienced codersAnd since we''re on religious topics, I hate the term "coder," it reminds me of the term "script kiddie." ;  It has been awhile since i have programmed or been here, but i got some questions for anyone i suppose.  1.  Do you use a different workspace for every project you do, and where do you prefer keep your files saved?  Talking like a newbie I am, jeez its been awhile. ;quote:Original post by thomashun   1.  Do you use a different workspace for every project you doSince you mentioned "workspace" I assumed you are talking about VC6. Workspace can contain one or more projects. If these projects are somewhat related to each other, I put them in one workspace. But if they are not related, separate workspace.quote:and where do you prefer keep your files saved?Project directory?edit:to OP. Make it clear and stay consistent througout the project.   [edited by - alnite on February 19, 2004 6:29:47 PM];quote:Original post by jpetrie  quote:my coding loins are beggining to stir once more.Oh man, I SO did not need to know that.Do I detect a transmetropolitan fan..Coding style is something that evolves with the artist. You learn the basics, then you write your own code and see what it looks like.You work out where you need to put comments. Work out how the blocks should be arranged.Style sort of a personal taste thing. Armand -------------------------It is a good day to code. ;  I appreciate all the help you guys can give, i almost forgot how great this place,gamedev.net, was.  Off topic but did any of you see that you can vote for your favorite tech tv girl at playboy.com, and they may or may not pose depending on who wins. ;  I voted for Sarah Lane.  High probability she won''t do the pose, but I can''t stand letting Morgan Webb take it unchallenged...Back OnT:Header style:large area consisting in all the following areas.  I can''t quantify itclass names: I don''t use prefixes (C____, I____, etc.).  Mostly this is because it''s worthless to distinguish, as you can have a pointer to an interface, and anything derived from an interface isn''t strictly an interface (like the retarded COM base interface, IUnknown.  By the semantics of inheritance, every COM object inexistence IS-AN Unknown.  That''s just wrong and dumb.) The C_ prefix is also abused by many on non-concrete classes, so it causes more trouble than it''s worth in my book.  (all the above is, of course, simply MNSHO)variable names:Prepend with m_ for members, g_ for globals where necessary.  If I was just getting started, I might or might not take up p_ as a convention, but m_ is the best change I''ve made to my style ever.  It makes parameters to member functions a lot nicer to come up with names for.use of the tab key to space blocks of code:I use expanded style, AOT Kerhnigan&Ritchie, just because it''s easier on the eyes.  It doesn''t conserve the vertical real-estate, which I might care about if I was radically hardcore, but things wind up pretty orderly and symetric, so that''s what matters.  I use tab stops equal to 4 spaces on all indented lines.  Everything between curly braces is indented another level in.Later,ZE. //email me.//zealouselixir software.//msdn.//n00biez.//miscellaneous links