Where to read up on (the best-practice in) source code formatting, for individual languages i.e. what are the conventions for naming variables etc., for indentation and where to place braces, how and where to include comments, etc.

For example for C Kernighan and Ritchie's book The C Programming Language and Linus Torvalds' Linux kernel coding style guide or Google's C++ Style Guide and for Perl at least perlstyle - Perl style guide.

Edit: Perhaps I should have asked "How to get a good start with coding styles".

Was it helpful?


I wouldn't give too much on such style-guides. They are a good start, but in the end you or your team will develop own coding-styles.

EDIT: Rob Kam made a comment, that he want to find out more about these 'starting-conventions'.

That's a good point. But mostly you will join existing projects, open-source-projects or commercial, and the people working on it already have a code-convention. In a company probably exists already a code convention. If you start a new project, start with the conventions of another project you did before.

If you really start a new project with a new language you didn't used before ... then you might start with conventions of another language that is somehow similar (i.e. for a new oo-language you can use conventions from Java or Smalltalk) and adjust your conventions as you gain experience for the new language. As I started programming in Java I used my Pascal-coding-conventions. Some of the pascal-conventions didn't work very good for Java, but with the time I dropped some old conventions and developed new.

S.Lott had the idea to look into an open-source-project written in the language of your choice. That's a good idea to get some suggestions about good conventions. Srikanth had the good idea to ask for good conventions here at Stackoverflow. A very good idea, because with the time Stackoverflow will become a good reference for coding-conventions this way.


What is better than a book is to locate open-source code in your preferred language.

Rather than a book -- the work of a few authors and editors -- working source code is a community project that meets highly-evolved community standards.

When asked by client to help with coding standards, I prefer to find a good Open Source project and provide a short standards document that says "Make it look like xxx". A good example that I use for Java style is the Apache Ant project.

Everyone has their favorite open source example project. Read some real-world, working code, and pick a favorite. Emulate that project.

I would use Google for it. For example, to search for Java Coding Guidelines, I will use this query or post in Stack Overflow and ask what are the recommeded coding standard guidelines for Java. It's difficult to point to a single source for all the languages.

I would suggest that you choose one for your company/project and stick with it and make sure it's a good standard.

I would really recommend to read uncle bob's Clean Code if you are concerned about code style issues.

There are three good places to look.

  1. Popular books on the language you're using.
  2. Open Source projects written in your language.
  3. Checkstyle-type utilities for your language.

If you use a tool like Checkstyle or PMD, be aware that many of the "rules" they enforce may be controversial. It might be helpful to check the documentation to find out which rules to be wary of.

Microsoft has a reference document with their coding conventions which may be useful to look at, even if you aren't using C#. Beyond style and basic conventions, best practices books recommended by others here, like Clean Code, are essential reading for creating maintainable, readable code that will make sense to future maintainers of your code base.

If you're using Visual Studio (and some other modern IDEs), basic inconsistencies with recommended conventions are automatically underlined (with suggestions on hover in recent versions of VS). In VS, if your team wants to use different standards, just open the Project properties and change settings for "Code Analysis" (last left-hand menu item). More here: Using Rule Sets to Group Code Analysis Rules

Hello and good day for everyone

Well i must say that it depends It depends on if you work for a company or if you work for you ;)

If you work for a company you mus accept the naming style and other rules

and for you, you only need to establish a style that everybody including yourself can instantly understand what and how

the brackets and others is your way

but as you said there are individual languages so they have own rules

and like Mnementh said every team have a way to coding maybe stricted or free way

Thats all with no more.... bye bye

There is the C and C++ style guides, a short page of links to style guides, coding rules, and discussions from USENET, maintained by Christopher Lott.

If you're a PHP developer these two guides are not to be missed:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top