Translation


by Transposh

Coding Best Practices for C – Part – 1

“Hello world” is the first lesson in any language. We always always try to improve our coding knowledge.  But for a professional development we should follow good and generic standards for writing a code. With my experience in C,I understood the fact,that writing a code is not a great thing. But writing a error free code in small span of time and  which can be referred or enhanced by other developers without any confusion makes a perfect code. As I strongly believe, Today’s best solutions becomes tomorrows Best Practices. We need to learn form our mistake and others experience to become perfect.

With this perception I would like to share my experience to enrich your Coding experience.

Here is some standard for coding C that you can follow to get the best result, and can save your life from Reviewer’s comments.

If you have below goals in mind:

  • Code should be robust and error free.
  • Code should be easy to use and understand.
  • Code should be easy to maintain.

This is for you.

Naming Conventions

General:

  • Clear and informative names are one of the best tools for creating easily understandable code. The name of any identifier should   succinctly describe the purpose of that identifier.
  • Avoid abstract names (in a global context) that are likely to be reused by other parts of the system.

File Names:

  • Header(.h) files should have the same name as the .c for header files dedicated to the .c.
  • File names should be made up of a prefix, underscore, base name, period and suffix.  File names should be consistent with the area of the application being modified.  File names should represent the content or role of the file.
  • Header file names should have the extension “.h”.
  • C Implementation (source) file names should have the extension “.c”

Function Names:

  • Function names should reflect what they do or what they return.
  • Do NOT re-use names of functions from the standards libraries (such as printf or strlen).
  • Function names should normally be formed from two parts: an action (verb) and an object (noun) of the action. Exceptions are query functions where the second part is not a noun, but the name should form a “question”.
    eg. GetSystemTime() SetStringLength()

Variable Names:

  • Variable names should be descriptive of the variable’s functions.
  • Constant names should be in all CAPS, with multiple words separated by an underscore, e.g.  MAX_PAGERS.
  • Macros, with or without parameters, should also be in all CAPS.
  • Enumeration constants and global typedef names should be in all CAPS with individual words separated by underscores, e.g. DATA_VALID.


Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Technorati
  • Webnews
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • blogmarks
  • Bloglines
  • BlogMemes
  • Ask
  • DZone
  • Blogosphere News
  • De.lirio.us
  • VoteForIt

Tags: , ,

24 Responses to “Coding Best Practices for C – Part – 1”

Comments

  1. forex account says:

    Awsome content, what template do you use in your blog ?

  2. free karaoke software says:

    What tamplate do you use in your blog? Very interesting articles

  3. free palm pre says:

    Excellent article, bookmarked for future referrence

  4. I never comment on blogs, but your awsome content have forced me to to leave some positive feedback

  5. zaklady bukmacherskie says:

    Nice work, your awsome content have forced me to to leave some positive feedback

  6. Delisa Swaim says:

    I just found your blog via Google by luck and must say it’s a very nice site. Will visit this blog again soon! My site is http://www.wordpressrobot.com/amazing-wordpress-plugin

  7. pebrook says:

    Always bear in mind that your own resolution to succeed is more important than any one thing.

  8. What blog script do you use on your site ?

  9. Etwas OT, aber was ich mich immer schon gefragt habe, warum T-Shirt Druck so teuer ist? Ich meine, die ganzen T-Shirt Drucker wollen knapp 20€ für ein normales T Shirt mit meinem eigenen Motiv haben. Ich suche jetzt aktuell für meine Band einen Anbieter, der mir Kleinserien druckt (so 10-20 stk). Kennt da jemand einen preiswerten Anbieter?

  10. Perfume says:

    Who reads papers when they have such a informative website to read. I was really asking myself on this matters so I went to Yahoo, typed my question and voila, here I am. Such a wonderful surprise to get to your site. Thank you for your time and for this great post. Thank you cute search engine for bringing me here.

    Goodbye!

  11. Eli Byon says:

    Actually, this seems a pretty decent blog, and since I’ve contemplated entering the 21st Century, you’re a good source of advice.

  12. I am a great lover! Appreciate your sharing offering this

  13. free magazine websites says:

    Incredible report,I anticipate some more post from you.

  14. Caryn Vanduynhoven says:

    hey,this is Caryn Vanduynhoven,just observed your Blog on google and i must say this blog is great.may I quote some of the writing found in the web site to my local buddies?i am not sure and what you think?anyhow,Thank you!

  15. Cecille Flesch says:

    Howdy there,just observed your web-site when i google something and wonder what webhosting do you use for your wordpress,the speed is more faster than my blog, i really need it.will back to check it out,thank you!

  16. Blaine Barklow says:

    Hello,just identified your web-site when i google something and wonder what web hosting do you use for your blog,the speed is more faster than my website, i really need it.will back to check it out,i appreciate it!

  17. Nanette Dalla says:

    hey,this is Nanette Dalla,just identified your Post on google and i must say this blog is great.may I quote some of the Post found in your website to my local buddies?i’m not sure and what you think?in either case,Many thanks!

  18. I’m not so convinced but nice share.

Pingbacks & Trackbacks

  1. [...] Best Practices for C – Part – 2Installing EmpathyCoding Best Practices for C – Part – 1Empathy for [...]

Leave a Reply