P
Poster Matt
Hi,
I've a few questions concerning style when programming C on UNIX systems. I
don't want to look like an amateur.
1. Having been programming in higher level languages for the last 15 years, I'm
finding it hard to get used to DEFINES in all capitals. Is it really frowned on
not to do so? Is CamelCase acceptable?
EG. '#define MaxNumFiles 1024' not '#define MAXNUMFILES 1024'.
2. My personal variable and function naming style is camel case, with variable
names beginning with a lower case char and function names not. Is that
acceptable, if not what is?
EG:
Variables: int numFiles = 0;
Functions: int CountNumFilesInDir(char* path);
3. Is there an accepted maximum line length? I've got a 24" monitor, if I reach
120 chars I start thinking this might not look great in someone else's editor.
4. Does anyone care where the pointer * is? I prefer keeping to next to the
type, rather than next to the variable name.
EG. I like: char* firstName; and not so much: char *firstName;
5. On a slightly different note, I've been handling my error messages by using
#define string constants in a header file. I saw some code which did this and it
looked good to me. Is that standard practise, if not what is?
EG. #define ErrorDirNotFound "The directory was not found."
There are so many style guides out there, most of them say contradictory things
at one point or another. What do the pros do?
Finally, before someone points this out... I know if I'm coding for myself, and
not following somebody else's stylistic requirements, I can do whatever I want.
However I'd like my code to be 'acceptable looking' to the wider UNIX C community.
Thanks and regards, etc.
I've a few questions concerning style when programming C on UNIX systems. I
don't want to look like an amateur.
1. Having been programming in higher level languages for the last 15 years, I'm
finding it hard to get used to DEFINES in all capitals. Is it really frowned on
not to do so? Is CamelCase acceptable?
EG. '#define MaxNumFiles 1024' not '#define MAXNUMFILES 1024'.
2. My personal variable and function naming style is camel case, with variable
names beginning with a lower case char and function names not. Is that
acceptable, if not what is?
EG:
Variables: int numFiles = 0;
Functions: int CountNumFilesInDir(char* path);
3. Is there an accepted maximum line length? I've got a 24" monitor, if I reach
120 chars I start thinking this might not look great in someone else's editor.
4. Does anyone care where the pointer * is? I prefer keeping to next to the
type, rather than next to the variable name.
EG. I like: char* firstName; and not so much: char *firstName;
5. On a slightly different note, I've been handling my error messages by using
#define string constants in a header file. I saw some code which did this and it
looked good to me. Is that standard practise, if not what is?
EG. #define ErrorDirNotFound "The directory was not found."
There are so many style guides out there, most of them say contradictory things
at one point or another. What do the pros do?
Finally, before someone points this out... I know if I'm coding for myself, and
not following somebody else's stylistic requirements, I can do whatever I want.
However I'd like my code to be 'acceptable looking' to the wider UNIX C community.
Thanks and regards, etc.