Industry Standards for Structuring Code and Comments

code-qualitycomments

I've worked with a number of professional teams and it seems that class code structure ranges from highly organized to completely cluttered. I did a project with the State of California recently and they required using specific Regions in my VB code, along with inline XML comments for auto-docs. It was very structured, but in many classes, there was more commenting than code. I'm just curious if there is an industry standard for code structure and commenting.

EDIT

Maybe a more appropriate question would be, what are some good practices to adopt for readability and maintenance and why? I want to set good coding habits early.

Best Answer

There are no standards that exist across all industries that govern code structure. I would doubt that any industry has industry-wide coding standards that deal with comments, file structure, and project organization.

The closest thing that you might find would be MISRA C, which are guidelines produced by the Motor Industry Software Reliability Association to ensure safe, portable, and reliable code in code that runs in the embedded systems in cars. However, as I don't work in the automotive industry, I've never had to deal with this.

Typically, code structure and guidelines are done at the organizational or project level, not across organizations or within industries. If you want examples of how to write good, clean, readable code, I suggest looking at Steve McConnell's Code Complete, Andy Hunt and Dave Thomas's The Pragmatic Programmer, Diomidis Spinellis's Code Quality: The Open Source Perspective, and Robert "Uncle Bob" Martin's Clean Code: A Handbook of Agile Software Craftsmanship - these are the canonical books on how to write the best code you can, regardless of language or platform. Many languages also have style guidelines, such as Oracle's Code Conventions for the Java Programming Language, which can serve as a foundation for an organization or project's code style rules.