Search code examples
ccoding-stylenaming-conventionsnaming

Should I abbreviate variable and function names in a library?


I am working on a C data structures library and I want my code to be clear, not having too much comments and still being readable, but I am struggling with naming.

  1. Should I use sinit() and linit() or stackInit() and listInit() to differentiate Stack and List functions?
  2. The variable holding a List should be list_t *ls or list_t *list?
  3. The variable that holds the size of each piece of data in a structure should be datasize or dataSize?
  4. Inside a structure I have a pointer to a function (given by the user) that would compare two elements, should it be cmp or compare?

I know all this questions are mostly the same, but I needed to make all cases in the code clear.


Solution

  • stackInit() and listInit() are more readable thean sinit() and linit().

    The same way the declaration list_t *list is more readable than list_t *ls.

    As for function names you are using the camel style then it is better when variable names differ from function names. So I would prefer to use datasize or data_size instead of dataSize.

    cmp is a common used synonym for the word compare or comparison. There is such an assembler command for Intel processors. So you may use either cmp , compare or comparison.