ethz-asl / programming_guidelines

This repository contains style-guides, discussions, eclipse/emacs auto-formatter for commonly used programming languages
139 stars 38 forks source link

All definitions should reside in source files. #6

Closed simonlynen closed 11 years ago

simonlynen commented 11 years ago

What about inlining?

If inlining is desired, the respective function definition should be moved to a separate implementation header which is included at the end of the header.

stephanemagnenat commented 11 years ago

And templates?

stephanemagnenat commented 11 years ago

And what about autodoc? In general, I put all autodoc in source file to keep headers clean, excepted for templates and inline members.

furgalep commented 11 years ago

I agree that all implementations should be in separate files. Can we have inlines/template implementations in implementation/MyClass.hpp. As Simon said, this should be included at the end of the class.

stephanemagnenat commented 11 years ago

Just a general comment: In my own experience, I realized that simplicity of access to the code is also important, and not only theoretical clarity should be considered. For instance, with small classes it makes sense to group them in a single pair of .h/.cpp files. I know that some people are using fairly sophisticated IDE, but some other people are using simpler editors. The file structure should not be uselessly complicated. I think that the common sense should have more importance than strict guidelines.

furgalep commented 11 years ago

Stephane, do you mean that, is some cases, we should relax this policy and allow inline functions defined in the header? I think that could fit under the rule:

  1. Any violation to the guide is allowed if it enhances readability.

The main goal of the recommendation is to improve readability and thereby the understanding and the maintainability and general quality of the code. It is impossible to cover all the specific cases in a general guide and the programmer should be flexible.

HannesSommer commented 11 years ago
stephanemagnenat commented 11 years ago

I fully agree with Hannes!

I also agree with you Paul that this could fit under the "rule violation because of common sense" rule. But I believe that as the guide we are writing is also a help for people not at ease with C++, it should help them to get a feeling how to code reasonably. One problem with beginners, just after very ugly code, is over-complicated code. I think that in the guide we should also give a feeling that coding has an artistic part, with an important common-sense component. Large classes holding significant part of the program logic should of course lie in their own files, but collections of support classes, especially when they are inter-dependant and templatized, are better grouped in a single or few files, in my opinion.

simonlynen commented 11 years ago

@HannesSommer Hannes could you integrate your comment to the style-guide? Thanks!