nameing
Greg Hunt
hunt at dg-rtp.rtp.dg.com
Wed May 1 23:52:21 AEST 1991
In article <1659 at babcock.cerc.wvu.wvnet.edu>, abmg at cathedral.cerc.wvu.wvnet.edu (Aliasghar Babadi) writes:
>
> I have seen different naming style for functions, variables,
> constants and types such as clear_sreen and ClearScreen, MAXBUFLEN and
> MaxBufLen
>
> What is the best nameing convention for
> functions
> variables
> constants
> types
>
> and why? Thank you for your suggestions.
There is no "best" way to name things. You'll find a wide variety of
answers to your question, and you'll have to decide for yourself how
you like to write your own code. I think there are some common
groundrules, however:
1. Make your names clear and easy to read. AbCdEfG is probably not
a good name to use.
2. Make the names meaningful. Calling all your variables a, b, c, or
d is probably not a good idea.
3. Be consistent. If you always use lowercase for variable names,
then don't do something different elsewhere.
4. When editing someone else's code, either use the style they used
for consistency, or rewrite the whole thing in your style. Mixing
styles makes things harder to read.
As for my opinions on how to name things, these are the ways I like to
write my own code:
functions - always lowercase
variables - always lowercase
constants - always uppercase
types - always uppercase
macros - always uppercase
comments - always mixed cases, following the normal rules of
writing prose
Why? Well, I code primarily in C, and since the language itself is
lowercase, I tend to write the most commonly used things (functions
and variables) in lowercase, too. I think it makes the code easier
to read.
I use uppercase for things that are "different", like constants and
types. To me, it makes it easier to see them, and therefore makes it
more obvious that what you're dealing with isn't a variable or
function (so you can't assign things to it, for example).
Since typedef's of structures contain two names that are in different
namespaces (at least in some compilers), I use the same name for
both parts, just different cases:
typedef struct foo_type {
int first_var;
int second_var;
} FOO_TYPE;
For most things, like declaring a structure of this type, I use the
typedef name like this:
FOO_TYPE foo_thing;
There are some rare cases (like forward references) where you have to
use the structure name instead. That's what foo_type is for.
Those are my opinions. Hope this helps. Enjoy!
--
Greg Hunt Internet: hunt at dg-rtp.rtp.dg.com
DG/UX Kernel Development UUCP: {world}!mcnc!rti!dg-rtp!hunt
Data General Corporation
Research Triangle Park, NC, USA These opinions are mine, not DG's.
More information about the Comp.unix.misc
mailing list