FAQ
Search
Memberlist
Usergroups
Register
Profile

Log in to check your private messagesLog in to check your private messages   Log inLog in 

Coding Practices


 
Post new topic
Reply to topic
   LeahHTTPd Forum Index -> Core Development
View previous topic :: View next topic  
Author Message

dnakata
Site Admin


Joined: 07 May 2006
Posts: 15
Location: Vancouver, BC

PostPosted: Tue May 23, 2006 3:22 pm    Post subject: Coding Practices
Reply with quote

I've been told before that my coding style is "shit", but I'd like to keep the code-flow as coherent as possible.

For that reason, I ask that if you submit a patch of some kind, or if (heaven forbid) you have subversion access, to try and stick with at least my brace and declaration packing style:

Code:
int myfunction( int x, struct s_client *client ) {
      return 1;
}


Please note my placement of *, the spacing of the comma, and where the braces are sitting.

For longer functions, I do the following:
Code:
struct s_key_tree *lhttpd_add_config(   struct s_key_tree      *scope,
                              char               *name,
                              void               *source,
                              int                  len,
                              enum s_storage_type      type ) {


It doesn't format so well on the forum board, but pretend those variable declarations are lined up in columns.

Either method is fine, I'm not too picky, my only real annoyance is the placement of & and *, they should be right up against the variable (in my opinion), so even if you prefer:

Code:
const void
myfunction(int x, char *thatthing)
{


at least put the * against the variable, please.

The reason for this, is that from time to time when a prototype name needs changing, or the methods used for interacting with it change, this convention makes it easier to search and update those instances.

By hugging the * and & against the variable, a search for '&thatthing' versus ' thatthing' (note the space), or versus '*thatthing' would allow me to find places where the variable is being dereferenced, where it isn't, or when it's being referenced.

The reason I like to declare functions on a single line is because I can use lazy-man sed/grep to create header files. So, it isn't very important! Smile

Finally, if you create a function, or declare any datatypes of any kind (within reason, "int x" is probably okay, as long as it isn't a global) please document them using the Doxygen methods (explained on the Doxygen website). If you're lazy, just use my Doxygen comments as examples:

Code:
/*!   \fn   struct s_key_tree *lhttpd_add_config( struct s_key_tree *scope, char *name, void *source, int len, enum s_storage_type type )
   \brief   Add a key/value pair to a branch of a config tree.
   \param   scope   The branch to attach the pair to
   \param   name   The key name to add
   \param   source   A pointer to the value
   \param   len      The value size in bytes
   \param   type   The type of contents in source
   \returns A pointer to the new keypair.
*/


This helps you, me, and everybody else who feels like fiddling in the source, or who wishes to write their own interface.
Back to top
View user's profile
Send private message
Visit poster's website
Jabber
Display posts from previous:   
Post new topic
Reply to topic
   LeahHTTPd Forum Index -> Core Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB© 2001, 2002 phpBB Group

SoftMetal theme by Macthink