bell notificationshomepageloginNewPostedit profile

Topic : Re: Where do I start with C++ documentation? I am new to programming and am entirely self-taught. I have reached a point in my writing where a solid grasp of documentation standards would be greatly - selfpublishingguru.com

10% popularity

Find a style guide and stick with it.

Style guides are more than just comments - they cover all parts of your code from how you name your variables to how you structure your code. Good style guides are designed to keep your code as maintainable as possible, with an emphasis on readability.

There are a number of style guides you can follow. Here is Google's C++ Style Guide. For the moment, you are mostly interested in the naming, commenting, and formatting sections, but you'll learn a lot from reading the other sections as well. Good style guides provide rules, explanations for why those rules exist, and examples.

The most important rule is to pick a style and stick with it. If you are consistent then both writing and reading your code becomes easier.

Quick and dirty rules of thumb

If you don't want to read through the style guide, my rule of thumb is that it should be possible to use a function without having to read the code. That means it should be completely comprehensible from the name and docstring. That usually means fully explaining what each of the arguments do, and that the return value means. If your code expects particular units (meters, seconds, etc), always describe what units you are using.

If, after returning to a piece of code after a little while doing something else, it takes you more than 10 seconds to figure out what a piece of code is doing or why it is doing that, add a comment.


Load Full (0)

Login to follow topic

More posts by @Pierce369

0 Comments

Sorted by latest first Latest Oldest Best

Back to top