-
Notifications
You must be signed in to change notification settings - Fork 24
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
Initial style guide #103
Initial style guide #103
Conversation
I would like to call attention to the following potential sources of controversy:
This PR currently includes guidelines that I find acceptable. I regard most of these as bikeshed issues, and I do not feel strongly about most of them. I'm happy to discuss them further, though, since more discussion and consensus now will make things go more smoothly later. |
I would also appreciate opinions regarding where we put comments. It is a bad idea to duplicate comments between header and source files. My question is, "should documentation comments be placed in header files, or in source files?" This includes any file-level descriptions about what modules do. I think they belong in source files, except in the case when multiple alternative source files implement the same API, and that API is described in a common header file. This is because
|
It should not be necessary to copy the license everywhere. It should not be necessary for each file to contain a marker that specifies its own name. It should not be necessary for author emails to be provided.
I feel the same -- it looks unnatural to me, but the reasoning behind doing it as Barr prescribes makes sense. I'm OK with following Barr.
I agree we need consistency above anything else. Removing the headers seems like the easiest way to achieve compliance. Barr gives the following guide line, which I think is sufficient and does not require headers, although it does not forbid them:
I prefer to keep things simple and avoid redundancy. If we require authors to be listed and refer to the
I don't mind this. The same is true in most Java style guides. The "TAG" acronym is cute because it is recursive, but there is seems no need to have the "T" as "advance grant" doesn't appear to be ambiguous.
I'm with Google on this one.
I have never followed this convention and haven't seen it being used much. Should we? Seems a bit excessive to me.
There are two things I personally don't like about Barr:
In other words, I (strongly) prefer:
over
|
I think writing comments at the interface is preferable. Ideally, we'd leverage something like Doxygen's implements command to inherit the interface description and supplement it with implementation-specific details if needed. |
I think that all of the comments @lhstrh gave above seem reasonable. As for Hungarian notation: Honestly, I don't know if it is a good idea. It's hard to determine whether things like this are good practices because formal evaluation of productivity in software doesn't seem to work. However, I think it plausible that Barr is right about it because
The I also am unsure why Barr doesn't include a prefix such as Given that this notation is reputed to be really annoying to those who don't like it, it might help for @edwardalee to chime in if he cares. |
I can't find a rule 7.2 in Barr nor any mention of Hungarian notation in Barr, so I'm not sure what is being proposed. Hungarian notation was developed by Charles Simonyi (who happens to be Hungarian), who was the lead developer of Microsoft Windows, not what I would consider a model piece of software. I've never been a fan of certain aspects of Hungarian notation, especially including types in the notation, and prefer to have a decent IDE, to heed compiler warnings, and to have a good type checker. In C, names can be used to compensate somewhat for limitations in scoping rules, e.g. to prefix globals with |
Sorry for the confusion. I wrote 7.2, but I meant 7.1. It's on page 48, which is the 60th page appearing the the PDF. The idea is to use a Recently, I also commented that the Maybe this is too complicated, and I'm happy to just ignore this part of the style guide. There's really no good reason why I raised this issue, other than the fact that it was in this style guide which I picked arbitrarily, and that I was intrigued by the idea that marking what is a pointer or a pointer to a pointer could help in navigating certain data structures. Incidentally, I'm not sure the |
(By the way, the same document that forbids leading underscores also forbids type names ending with Since our code base is pretty small, the number of naming conflicts might be rare -- we don't seem to have had any yet. |
I think we do have quite a few though: |
Right. That means that if we followed that guideline, we would have to change a lot of code, and it would be a mess. |
An unrelated observation is that if this discussion becomes too complicated, and if we end up creating a lot of exceptions to the Barr standard, we could just abandon this particular attempt at a style guide and start from scratch (while keeping an eye on resources like MISRA and this) so that our style guide is as close as possible to what we already do. I really just want the process of adopting a style to be as painless as possible... |
I think the most pragmatic thing is to point to a style guide for the meat of it and mention a short list of exceptions. Are there other style guides to consider that might be closer to what we want? If not, I think we're doing the right thing already. |
We have had some naming conflicts. We had defined macros named MIN and MAX, which I had to rename LF_MIN and LF_MAX to get our code to compile with the Nordic base for the nrf52. As for the leading underscore, we could avoid it if we refactor header files so that user code never has these variables/functions in scope and so that we entirely eliminate any #include of C files (I think most of these are gone, but not all?). |
It's funny that Barr uses the |
This commit - Forbids horizontal alignment - Forbids all forms of Hungarian notation - Forbids the use of comments as explicit section headers - Defines a stance on doc comment placement - Fixes two small mistakes in the templates: Private procedure implementations should appear after public procedure implementations, and globals must be declared (not defined) in header files.
I think my latest commit addresses the discussion we had above. The commit message itemizes the changes. |
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.
Very nice!
This reverts commit 5837661.
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.
LGTM. One downside of this is that it requires everyone to go read Barr, an 87 page document...
I agree that this is a problem. My goal was not to create busywork, and I had hoped that it would be possible for people to mostly continue with the existing style and only sometimes refer to Barr to answer questions and resolve disagreements. If several people end up having to read it all cover-to-cover, that would be unfortunate, but maybe having a style guide is worth it to us. |
The following are required before this PR is merged:
The following are left for future PRs: