-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propose Documentation for Software Best Practices, Coding Conventions, and Style #358
Propose Documentation for Software Best Practices, Coding Conventions, and Style #358
Conversation
Reviewers may find it easier to review the attached PDF rendering of this: CODING_STYLE_GUIDE.pdf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use ascii doc here, given we're using that for other things.
@rwalker-apple and I will try that, just need to get something that will preserve the desired formatting and automatically get us from the gDoc form to AsciiDoc automatically on the first pass without hand-writing it. |
441db33
to
62e0442
Compare
Done; now in AsciiDoc. |
Done; now in AsciiDoc. |
Nice work! I think the best way to iterate on this is to accept as-is and use PRs to debate updates. There are some bits that don't match current tree rules, but fallback to "When in Rome..." @woody-apple any thoughts? |
Resolved. |
I’ll work on comments this weekend and early next week, but I’d like to pare down some of this to add flexibility for developers. |
@woody-apple it seems asciidoc/asciidoc is not maintained anymore. Should we use it or choose another tool? |
asciidoc maintenance and support has transitioned to asciidoctor, and is still supported by pandoc and Google Docs |
@woody-apple have you had time to review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm struggling a little bit with the scope of the document here. I like the Doxygen push, as well as much of the C/C++ pushes, but this feels a little overly prescriptive - as well as duplicates clang-format/restyled.
Can this be reduced somehow to something more palatable for people to consume + read? (This took me a while to review...)
|
||
image:CODING_STYLE_GUIDE-figure1.png[Figure 1. Graphical summary of the | ||
qualitative and quantitative applicability to Project CHIP software.] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very tied to C/C++. We will have lots of Objective C and Swift Code, as well as I'm assuming Java, etc - I don't want to give the impression in a document that we discourage other languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the original source of this document was applied to shared, horizontal embedded C/C++ infrastructure projects so this document targeted that world.
We can definitely create a taxonomy of documents/guides fo other languages / platforms. I'm open to suggestions and crowd-sourcing. This was a bootstrap effort to get us started that @rwalker-apple and I suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd really like to pare down the scope of this document, to something that is 2-3 pages max, so people can really digest this. I think the verbosity here makes it something that nobody will actually read... (maybe that's just me)
leveraged through toolchain-compatibility preprocessor macros. | ||
|
||
|link:#h.cdtfddg825xl[2.2] a| | ||
Project CHIP embedded software development uses the ISO14882:2011 (aka |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we define embedded vs non embedded systems?
Additionally, I assume we're supporting assembly where required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely can support assembly where required. My experience has been that it's vanishingly rare and those that need to deal with it, know what they're doing enough that we didn't need to be prescriptive about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we could distill this down to something might lighter and more digestible. "By default, we should use C/C++, but are open to other languages on a case by case basis."
specifically, the use of the non-local scope inline functions should be | ||
avoided. | ||
|
||
|link:#h.w81efp46u07r[3.1.2.2] |Inline functions should be used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Not sure I agree/understand. Aside from that we should avoid "thou shalt" - unless it's explained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The up front content is a summary table. The summary table links to the full content along with motivation and rationale. Let me know what you think after the motivation and rationale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should handle these case by case, just feels odd to have this be stated unilaterally.
|link:#h.tjgjnfdzmvlt[3.1.2.4] |There should be no calls to the | ||
functions `setjmp` or `longjmp`. | ||
|
||
|link:#h.96ozmz48upvf[3.1.2.5] |There should be no calls to the C/C{plusplus} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree here. These can be highly valuable. Why are we denying these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The up front content is a summary table. The summary table links to the full content along with motivation and rationale. Let me know what you think after the motivation and rationale.
Totally agreed on the usefulness. We've encoded that usefulness mostly in the context of nlassert.h or CodeUtils.h macros that better decorate the usage.
|link:#h.w81efp46u07r[3.1.2.2] |Inline functions should be used | ||
judiciously. | ||
|
||
|link:#h.lznwwfek3mml[3.1.2.3] |There should be one `return` statement per |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disagree here, I understand some imported code bases like this, others won't - as well as more modern development. Is there a rationale here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The up front content is a summary table. The summary table links to the full content along with motivation and rationale. Let me know what you think after the motivation and rationale.
such files by using a dash (“-”) in the file name to indicate the | ||
subcomponent or subset of functionality. | ||
|
||
File names should be all lower case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense in Darwin land. Can we do this on a review basis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; we need to identify a taxonomy of style documents for the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can just remove this item then?
[[h.dux1t2sfd7li]] | ||
=== 4.2. Naming | ||
|
||
Names should be descriptive but not overly so and they should give some |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObjectiveC and Swift can be very verbose. Can we apply this at review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to identify a taxonomy of style documents for the project.
[[h.7g2jekkhysl3]] | ||
====== 4.2.2.2.1. Motivation and Rationale | ||
|
||
This is previously-agreed-upon long-standing convention. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where this was agreed on? I don't disagree, but seems like there could good exceptions to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad motivation and rationale here; this is a vestige of the document copy-and-paste. We can delete or come up with a legitimate motivation and rationale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's delete please :)
[[h.145w2jejpii6]] | ||
====== 4.2.2.3.1. Motivation and Rationale | ||
|
||
This is previously-agreed-upon long-standing convention. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad motivation and rationale here; this is a vestige of the document copy-and-paste. We can delete or come up with a legitimate motivation and rationale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's delete please :)
[[h.h1hnyi16kha7]] | ||
==== 4.5.2. Indentation | ||
|
||
Indentation shall be 4 space characters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restyled handles all this automatically... do we need to codify these in multiple places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See prior comment about "What the...?!". If we don't need it, we can drop this/these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should drop most/all style stuff, and collapse it to a single item:
• Style must pass clang-format, .editorconfig, .pretty, etc.
Generally, this was copy-and-pasted from an internal document. We can definitely flag things we don't like and eliminate or re-work them. In terms of clang-format/restyled, the automation is great and there may be no need to document the "Why did you chose this option for clang-format?". Those things that are documented were those we at least found internally tended to generate the most "What the...!?" conversations where the motivation and rationale were useful. |
|
||
|link:#h.imbb237rmsjp[3.1.2.12] a| | ||
Read-only methods, global variables, stack variables, or data members | ||
are read-only should be qualified using the C or C{plusplus} `const` qualifier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: that are
|
||
|link:#h.vuy3kslcw1c0[3.2.7] |Code shall not use exceptions. | ||
|
||
|link:#h.s7u364eurjpt[3.2.7.2] |In the rare case that Proect CHIP code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Project
years. Project CHIP and the source code it has produced have only | ||
existed for the last five of those 20 years. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guessing this is left over from a previous project, and even though this justification is even more relevant given the infancy of CHIP, we should fix the dating
7573d23
to
f96542f
Compare
@gerickson Thanks for all the time on this document! Can we find a way to pare this down to a 1-3 page document that people can read in maybe 10 minutes? I think that's the only way to have this be actually impactful - we need it to be consumable by our new developers :) |
That was the thinking on the up front summary, those what want the TL;DR can stop there. Those that want the motivation and rationale can read further. |
File names should be prefixed with ‘chip’. | ||
|
||
File names should follow the pattern | ||
_chip<component>[-<subcomponent>].\{c,cpp,h,hpp,m,mm}_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we standardize if h or hpp should be used for C++ files? I have seen that we predominantely use .h, however there are a few .hpp files and I found that inconsistent.
It would be nice if we could either say "everything is h" or "C/C-compatible is h, CPP is hpp". I would favour "everything is h" myself.
File names should be prefixed with ‘chip’. | ||
|
||
File names should follow the pattern | ||
_chip<component>[-<subcomponent>].\{c,cpp,h,hpp,m,mm}_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be guided based on how we include things.
If we generate a separate include directory, I would like to #include <chip/connection.h>
instead of #include <chip/chip-connection.h>
as the latter seems a bit smurf-named to me. As prior art for the shorter include, openssl includes openssl/aes.h
rather than openssl/OpenSslAes.h
. I believe shorter includes are more prevalent within the industry and developers are more familiar with it.
[[h.ft3tkwpjkeex]] | ||
==== 3.2.4. C{plusplus} Standard Library | ||
|
||
The use of the C{plusplus} Standard Library shall be avoided. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifying subsets may be useful instead of a blanket removal. While anything that uses dynamic memory allocation is bad, there are things that are probably useful, like algorithms or things that do not use memory allocation.
I would propose a whitelist approach here instead. I am thinking of <array>, <algorithm>, <climits>, <cmath> and such which likely do not introduce overhead but are very useful to have. Even std::unique_ptr may be useful for RAII (although more annoying to use due to custom deallocators when using the pool allocators).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the note that unique_ptr probably requires -fno-exceptions to not generate stack unwinding. I am not sure if we are ready to say chip compiles with that flag though even though we require no exception usage.
@rwalker-apple @gerickson per our last chat - what are the next steps here? |
I don't think there is one / are any. At minimum, the Doxygen content got factored out into a standalone document. The last discussion ended with a mandate that we spend no more cycles on this. If there are things that everyone comes to agreement across companies (and, at that, there does not even seem to be alignment within companies), we can bubble those things up and memorialize them in a from-empty-to-plus-plus approach rather than in a as-is-to-minus-minus approach. |
@rwalker-apple @gerickson I suggest we close this for now, then open up an organic document as things come in? Thoughts? |
|
Fine with me, but can we get that document up first? |
Closing in lieu of #1504. |
See here for such a document: #1504 |
Problem
CHIP will be composed of much software contributed from participating member organizations. However, for any new CHIP code, there should be documentation for software best practices, coding conventions, and style.
Summary of Changes
Proposed a documentation guide, in AsciiDoc format, for software best practices, coding conventions, and style.
Fixes #335