Different coding styles?
I''m gonna be starting a small game project with a few friends, and I was curious about something. Since we are all going to be working together, should we try to use the same naming convention for variables and functions, or just stick to our individual preferences?
For instance, I personally use hungarian notation for all my variables (which makes it easy to tell at a glance the type of variable as well as whether it is a local or member of a class) while one of my friends begins all variables with an underscore to differentiate between variables and functions.
So my question is:
Should my team try to come up with a standard to use, or have everyone use their seperate styles (thus complicating the readability of the code since there will be 4 distinct styles mixed together). And if we should use a standard, is there any convention out there that is considered the standard (ie hungarian notation)?
- Houdini
It would probably be a very good idea to stick to one coding style for everyone that is working on the project. As to what convention to use, that is up to you.
There really isn''t a ''standard,'' but I suppose that Hungarian notation (yuck, barf!) might be almost considered one because of the fact that Microsoft uses it, and as we all know, they run the universe. I personally don''t like that style at all because I feel like it turns a reasonably clear variable name into a mess of prefixes. I prefer something more like the ''Unix style'' consisting of relatively short variable names with underscores instead of capital letters to increase readibility. But, as I said, that''s just my opinion. If everyone in your group likes to code using Hungarian notation, then do it by all means.
There really isn''t a ''standard,'' but I suppose that Hungarian notation (yuck, barf!) might be almost considered one because of the fact that Microsoft uses it, and as we all know, they run the universe. I personally don''t like that style at all because I feel like it turns a reasonably clear variable name into a mess of prefixes. I prefer something more like the ''Unix style'' consisting of relatively short variable names with underscores instead of capital letters to increase readibility. But, as I said, that''s just my opinion. If everyone in your group likes to code using Hungarian notation, then do it by all means.
A standard is definately a good idea, and preferably one that improves readability and ease of documentation.
However, choosing one is up to you.
I used to think Hungarian Notation was the only way to achieve anything like readability, probably due to my professional necessity of having to wade through reams of Microsoft Code.
However, now I''m working on adding to the Mesa3D library, I''ve found that other notations can be just as acceptable, and perhaps less cumbersome than the endless-prefixes style of Hungarian.
PostFixes, for instance, have the benefit of grouping similarly named things together alphabetically, something that can be a bonus in IDE''s such as visual studio.
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
However, choosing one is up to you.
I used to think Hungarian Notation was the only way to achieve anything like readability, probably due to my professional necessity of having to wade through reams of Microsoft Code.
However, now I''m working on adding to the Mesa3D library, I''ve found that other notations can be just as acceptable, and perhaps less cumbersome than the endless-prefixes style of Hungarian.
PostFixes, for instance, have the benefit of grouping similarly named things together alphabetically, something that can be a bonus in IDE''s such as visual studio.
#pragma DWIM // Do What I Mean!
~ Mad Keith ~
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
This is where the beauty of classes can solve all problems. If you base you project around C++ class, all you have to do is sit together and create the interface and the specifications for the classes. Each member can implement the classes however he or she wants and with whatever style.
One side note. Make sure the code is readable. If its not, it will be very hard to debug.
Also standards rarely ever hurt.
Domini
One side note. Make sure the code is readable. If its not, it will be very hard to debug.
Also standards rarely ever hurt.
Domini
Domini Miracle Man Studios
>> Should we try to use the same naming convention for variables and functions, or just stick to our individual preferences? <<
Come up with a standard that everyone uses or else the code will be somewhat hard to read. I haven't worked on any big projects yet, but I know from working on several smaller projects that using the same coding style will make everything easier to read.
/. Muzzafarath
Visit my website, Mad House Software
Edited by - Muzzafarath on May 22, 2000 2:02:30 PM
Come up with a standard that everyone uses or else the code will be somewhat hard to read. I haven't worked on any big projects yet, but I know from working on several smaller projects that using the same coding style will make everything easier to read.
/. Muzzafarath
Visit my website, Mad House Software
Edited by - Muzzafarath on May 22, 2000 2:02:30 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
what *is* the hungarian notat...?
========================
Game project(s):
www.fiend.cjb.net
========================
Game project(s):
www.fiend.cjb.net
=======================Game project(s):www.fiend.cjb.net
Hungarian notation is a variable-naming convention that was developed by a Microsoft employee. Basically, all variable names begin with one or more lowercase letters that indicate the variable type. Here are some of the prefixes you''d use for variable types:
b Boolean
by Byte or Unsigned Char
c Char
w WORD
dw DWORD
h Handle
i Int (integer)
l Long
n Short Int
p a pointer variable
s string
sz ASCIIZ null-terminated string
m_ member of a class
So, instead of naming variables as such:
int count;
byte level;
char *name;
You would name them as so:
int iCount;
byte byLevel;
char *szName;
If these variables were a member of a class (rather than a function) they would be written as so:
int m_iCount;
byte m_byLevel;
char *m_szName;
While it may take a while to get used to, it has some big advantages. If you are looking at someone elses code and you see a variable you know right away a.) What type it is, and b.) Whether it is a part of a class or a local (or perhaps global) variable. It makes other people''s code 100x easier to read, imo.
b Boolean
by Byte or Unsigned Char
c Char
w WORD
dw DWORD
h Handle
i Int (integer)
l Long
n Short Int
p a pointer variable
s string
sz ASCIIZ null-terminated string
m_ member of a class
So, instead of naming variables as such:
int count;
byte level;
char *name;
You would name them as so:
int iCount;
byte byLevel;
char *szName;
If these variables were a member of a class (rather than a function) they would be written as so:
int m_iCount;
byte m_byLevel;
char *m_szName;
While it may take a while to get used to, it has some big advantages. If you are looking at someone elses code and you see a variable you know right away a.) What type it is, and b.) Whether it is a part of a class or a local (or perhaps global) variable. It makes other people''s code 100x easier to read, imo.
- Houdini
Like Domini, I''m a great believer in using classes.
If you are using C++ and classes, then break down your game into totally seperate parts, thus ''encapsulating'' the various parts of the game.
E.g. whoever is doing the in-game music should only need to pass everything wrapped into one class which the game engine buff can include and make the relevant calls to.
By doing this, the only naming you should need to standardise is the class methods/functions. Everything else is behind the scenes and you can all work to your own preferences. I hope my employers don''t read this or I''m in trouble!!!
Marty.
If you are using C++ and classes, then break down your game into totally seperate parts, thus ''encapsulating'' the various parts of the game.
E.g. whoever is doing the in-game music should only need to pass everything wrapped into one class which the game engine buff can include and make the relevant calls to.
By doing this, the only naming you should need to standardise is the class methods/functions. Everything else is behind the scenes and you can all work to your own preferences. I hope my employers don''t read this or I''m in trouble!!!
Marty.
An interesting side note which I thought I''d point out is that hungarian notation was developed when C was still the language of choice among most developers. Since then, C++ has become more widespread, and since C++ encourages user defined types, it does sort of add a new complexity to hungarian notation (since hungarian generally only deals with the basic types). Of course, you could use a prefix like "cl" for instances of classes -- but wouldn''t that defeat the purpose of Hungarian notation?
Just some thoughts (mainly because I''m curious as what others do about this)
--TheGoop
Just some thoughts (mainly because I''m curious as what others do about this)
--TheGoop
While C was probably the language of choice among developers when Hungarian notation was developed, it was most likely originally used for assembly language, in which all you know about a variable is its size. Another supporting point is that Windows (even more so the older versions) was/is written mostly in assembly.
In my opinion, Hungarian notation hurts readability and that''s really the point of using naming conventions.
I don''t know how "LPCSTR lpszstr;" can be more readible than "const char *str"...
In my opinion, Hungarian notation hurts readability and that''s really the point of using naming conventions.
I don''t know how "LPCSTR lpszstr;" can be more readible than "const char *str"...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement