Announcement: Be excellent to each other.


Caravel Forum : Caravel Boards : Development : Coding standards
New Topic New Poll Post Reply
Poster Message
Schik
Level: Legendary Smitemaster
Avatar
Rank Points: 5381
Registered: 02-04-2003
IP: Logged
icon Coding standards (0)  
I was wondering if somebody could give me a quick rundown on the coding standards used in DROD? The variable naming is a bit (read: a lot) different than what I\'m used to, though I\'ve seen similar to your style in books.

I tried to do mine similar to what I saw, but going back through it I see places where I use my own conventions. It would be easier for me to follow DROD conventions given a couple quick & easy rules.

Thanks...

____________________________
The greatness of a nation and its moral progress can be judged by the way it treats its animals.
--Mahatma Gandhi
02-19-2003 at 09:39 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: Coding standards (0)  
Schik wrote:
I was wondering if somebody could give me a quick rundown on the coding standards used in DROD? The variable naming is a bit (read: a lot) different than what I\'m used to, though I\'ve seen similar to your style in books.
Yeah, this is the \"hungarian notation\"--a gift from Microsoft. Different programmers choose different prefixes to indicate the type of variable, but the ones I use (with some inconsistency) are:

w - unsigned short
n - signed short
dw - unsigned long
l - signed long
b - boolean
byt - byte
c - char
sz - null-terminated char array
wcz - null-terminated wide char array
str - STL string
wstr - STL wide char string
dbl - double
sgl - single

p - pointer to something. If it is one of the above types, I\'d probably combine the prefixes, i.e. pl.

h - handle to something.

arr - An array of something.

I tried to do mine similar to what I saw, but going back through it I see places where I use my own conventions. It would be easier for me to follow DROD conventions given a couple quick & easy rules.
I\'d feel bad about imposing rules on you. However, I understand that it is good to be consistent. I usually emulate the style and design of other code when I join a project and take some pride in staying flexible. In the DROD project, I\'ve let people code in whatever style suited them. When I added code to functions they authored, I even tried to write my code in their style for that one function. So most style things don\'t matter too much to me.

Mainly, I like to see comments that describe what functions and code inside them do.

It would be nice to follow the verb-noun naming convention for functions, and try to reuse existing verbs when appropriate. As much as possible, it should be clear what a function does by its name. I have made some spectacularly long function names to do this.

The only global variables we have (module-scope declarations with extern declarations in other modules) are singleton objects. Well, maybe there is an exception somewhere, but I don\'t like global variables. Generally, variable scopes should be made as small as possible, sacrificing convenience and performance at times to make safer and clearer code.

Feel free to load your code up with ASSERT macros to catch debug errors. Functions should generally not return for debug errors, however there are many times when I break this rule because I don\'t want to crash a released app. In other words, I concede at times that I might not catch a particularly important debug error before the release is made.

Exception-handling (try...catch) is not used.

Use one of the C++ cast operators for casting (static_cast, dynamic_cast, reinterpret_cast) instead of the C-style casting.

Multiple inheritance is done, but reluctantly. It\'s preferred to embed extra classes as members or revise the base classes to avoid multiple inheritance.

Ack. I don\'t want to go on and on. I think the project shouldn\'t contain much in the way of coding standards, but here I go spewing them out. Mainly, just remember to comment things, and I can catch most \"offenses\" on review and change code myself if it\'s important.

Thank you for asking (and I hope you don\'t regret it :) ). It is most conscientious of you!

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
02-19-2003 at 10:51 PM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
Schik
Level: Legendary Smitemaster
Avatar
Rank Points: 5381
Registered: 02-04-2003
IP: Logged
icon Re: Re: Coding standards (0)  
erikh2000 wrote:
Yeah, this is the \"hungarian notation\"--a gift from Microsoft.
I never cared much for this notation, for the simple reason that it only seems to work for built-in types. What about my class CFoo? But that\'s irrelevant, and I certainly don\'t want to try to change anything like that - I just wanted a list (thank you) because I renamed a few variables about 20 times thinking \"no wait, the w is BEFORE the z...\"
Mainly, I like to see comments that describe what functions and code inside them do.
Yes, I\'ve tried to put the same headers on the functions as other existing ones.

I have made some spectacularly long function names to do this. So I noticed. :) But I see this as a good thing (within reason).
Thank you for asking (and I hope you don\'t regret it :) ).
Not at all - I just took a look at the coding standards document we have at work - 25 pages covering 112 rules. :eyes



____________________________
The greatness of a nation and its moral progress can be judged by the way it treats its animals.
--Mahatma Gandhi
02-20-2003 at 12:24 AM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores Quote Reply
ErikH2000
Level: Legendary Smitemaster
Avatar
Rank Points: 2794
Registered: 02-04-2003
IP: Logged
icon Re: Re: Re: Coding standards (0)  
Schik wrote:
I never cared much for this notation, for the simple reason that it only seems to work for built-in types. What about my class CFoo?
I\'ve had my philosophical ponderings and decided I liked using the notation for some frequently-occurring types. And a lot of my bias towards it has to do with working on projects with other Windows programmers where certain conventions come up a lot. You can use it or not use it--no big deal.

I just took a look at the coding standards document we have at work - 25 pages covering 112 rules. :eyes
I\'ve written a couple docs like that for projects. On commercial projects, it\'s about impossible to get programmers to follow them without sacrificing a friendly work environment. On open source projects, well... you don\'t want to look a gift horse in the mouth. My approach now is to choose disputes very carefully, and let code be less than perfect.

Sometimes, I wish there was something like Generally Accepted Programming Priniciples for C++, and everybody would just learn this one time and use it in all the different companies and projects they visit. And also it should be no more than 10 pages long and be written by somebody else besides me, because if you say \"here are somebody else\'s standards for you to follow\" to a team, it goes over better than \"here are MY standards for you to follow.\"

-Erik

____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals | twitch stream | youtube archive (NSFW)
02-20-2003 at 01:15 AM
View Profile Send Email to User Show all user's posts This architect's holds Quote Reply
Schik
Level: Legendary Smitemaster
Avatar
Rank Points: 5381
Registered: 02-04-2003
IP: Logged
icon Re: Re: Re: Re: Coding standards (0)  
erikh2000 wrote:
because if you say \"here are somebody else\'s standards for you to follow\" to a team, it goes over better than \"here are MY standards for you to follow.\"
The only reason I\'d have a problem with the standards is if I strongly disagreed with them for a non-cosmetic reason. If the standard said every variable should be a void* and be cast when used, and should be named incrementally starting with a00001, I\'d have a problem. If they said that the { should be at the end of the if() line instead of on a new line.... who cares.

In other news: I\'ve been running SGI drod through exceed on my PC, and it\'s very slow, but it looks like I\'ll be getting an SGI on my desk very soon, so that will make testing a lot less painful. :)



____________________________
The greatness of a nation and its moral progress can be judged by the way it treats its animals.
--Mahatma Gandhi
02-21-2003 at 08:18 PM
View Profile Send Private Message to User Send Email to User Show all user's posts High Scores Quote Reply
New Topic New Poll Post Reply
Caravel Forum : Caravel Boards : Development : Coding standards
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.