-
-
Notifications
You must be signed in to change notification settings - Fork 39.9k
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
Do we have an official coding style? #723
Comments
Please... No... Wars have been started over less. |
I'm not really looking for a debate, personally I'm happy with whatever @jackhumbert or someone else tells us to use. I would just like to see some sort of consistency, but if the coding style is "write in whatever style you personally prefer", I can accept it too. |
Definitely agree about the GPL stuff - that's been something we've been needing to address for a while. Maybe that should be a separate issue where we can spend some more time discussing what we need to do for compliance. For the coding style, let's just run with OTBS, lowercase + underscored variables, uppercase + underscored enums, and spaces for indents. I'm not too worried about indents though, and we probably don't need to worry about what people do inside their own keymap. |
I loathe OTB. :P Like I said, it is a very touchy subject. Why not just leave it as is? |
@jackhumbert Thanks Just one more question, the Wikipedia page doesn't make it fully clear if you should put the brackets on the same line for functions, or if it's just for control statements. And yes, I agree, we shouldn't worry about the coding style for keymaps. @IBNobody |
Opening brackets on the same line for functions and control statements :) OTBS/K&R is pretty standard in C from what I've seen :/ |
Sure, but what would happen if we just kept doing what we are doing? I do not like to code in OTB, but I don't begrudge anybody else their style. :P Allman is standard too. NASA uses it in their C guidelines. |
K&R 👍 |
Although I have no strong opinion on this. I think compliance with TMK and perhaps do something more to promote that style in the contribution docs |
@DidierLoiseau If you can suggest a method to autoformat between K&R and Allman on submit, I'd be onboard. |
Is there a way to integrate that into the git checkin process, though? |
Use Git hooks. We could add a script say, It's best to allow some sort of override, just incase it causes someone an issue. Also our preferred usage will need documenting of course. Cross platform issues will probably be the biggest issue, but at least it would help people stay standardised. We can also recommend using editor plugins / formatters which also enforce K&R. |
Will it easily unKR the code too? I would be willing to try something, provided it works with the Windows toolchain. |
I recommend reading the docs and trying the tool standalone to see how it works. Specifically here, it outlines that styles are an basically a collection of rules. |
A commit hook is indeed a solution, but TBH I would consider it as a last resort solution. I don't really like the idea that you can't see what will be committed, and that it could be difficult to restore if it gets messed up. In fact, I am using Eclipse to work on QMK, and it is able to format code automatically on save if desired. I hadn't enabled this feature and now I remember why: it completely messes up the keymaps! And unfortunately, it does not support to turn it off through comments (feature request, vote for it!). Another option would be to configure tools to analyse the code and output warnings when it does not respect the style. Some of these tools can do static analysis and detect potential bugs too. Such a tool could probably be configured to run as part of the build that runs on merge requests for example. |
I'm also averse to this. But, we don't have to configure indent (or any other tool) indiscriminately. Keymap files (and anything else we choose) can be excluded. |
We can also lint / style check and provide warnings instead. I think it's simple enough to exclude keymaps programmatically. Even if indent doesn't support comment matching, we can easily achieve the same result. |
I'm going to close this issue for now. To summarize the situation with code style:
|
can we ask that methods be documented, it's really hard to figure out what is going on if your new here |
@jceaser We have some efforts underway to help people in your position. We could use more and better comments, and we have also been working to improve our documentation. One piece of that that may help you is a rough draft of one of those documents: https://github.com/qmk/qmk_firmware/blob/docs/docs/understanding_qmk.md |
As I finally will start to write some actual code for QMK, as a part of the effect system described in #717. I started to wonder about the coding style.
We seem to use many different styles, even the
quantum.c
file is not consistent. The codebase has a mixture of at least theseFor the reference, the only coding standards that the TMK firmware have is the following
It would be nice if we had an official standard for at least these common cases. I'm not suggesting that we change existing code, but new code should probably follow a common standard.
On a different, but somewhat related note. The QMK firmware has to use either GPLv2 or GPLv3, due to the TMK roots. So we should probably make it fully compliant, by adding the appropriate headers and add a "COPYING" file. This is something that has bothered me for some time, and today I saw this pull request for TMK, which reminded me about it again.
The text was updated successfully, but these errors were encountered: