Skip to content

0.a. Coding Style

Bob Frazier edited this page Dec 31, 2016 · 1 revision

Coding Style

Coding style for this project is "readability". However, I prefer Allman Style with 2 character indents and no hard tabs.

Pull requests that use K&R style for code changes, or that attempt to convert away from 'Allman Style', are likely to be rejected. That being said, if you want to make a code change suggestion or submit a fix, a pull request would be a simple way to go about it. Or you can post a patch (or a link to a patch) as an 'Issue'.

Comments in the code are welcome. Self-documenting code is easier for other programmers to understand. Also you should use as few 'magic numbers' as possible. If you must use a magic number, comment it and reference a tech manual or spec sheet as to why you're doing it. Additionally, avoid the use of global variables unless you have no other choice, especially initialized variables. See how the startup code handles those for reasons why you want to minimize their use.

Also, please consider that if Linus Torvalds would use profanity after reading your code, it's probably a good idea to clean it up before submitting. I find myself agreeing with Linus on lots of things...

For CPU-specific code, it's a good idea to review the cpu-specific header files. For the xmega64d4, the file name is 'iox64d4.h'. Nearly all of the bit and port definitions are in there someplace. It's best to use those whenever you can. If you just can't find the value, _BV(n) works for individual bits (just comment it, please).

A lot of the libraries and source were once written in K&R (or similar style). Code borrowed from the Arduino IDE is very likely "fixed" so that it's more readable (aka 'Allman Style', 2 character indents, no hard tabs). I'd like to keep this going so that the coding style is consistent (and I don't 'fix it' in a fit of rage on the next commit). However, due to time limitation, I may not get to "all of it", and so you may see a mixture of styles in areas I haven't edited (yet).

I did a more in-depth write-up on coding style for THIS project, which is a long-term work in progress that isn't even remotely completed. However, it has a lot of documentation, including the coding style guidelines.