GNOME Bugzilla – Bug 761465
Start a discussion to ensure/fix coding style
Last modified: 2016-02-11 02:05:38 UTC
So, at the current moment, the coding style on seed is bad, really bad. it uses all the kinds of things, tabs for indentation, 4 space for indentation, 2 spaces for identation. GNU brackets, normal indented brackets. Comments with mixed space and tabs. All the kind of things, and TBH, I'm also the author of some of those mistakes too. I would like to make a suggestion: Include a doc/CodingStyle.txt documenting the kind of style we want and adding a .clang-format to ensure that every piece of code follows that format. As an example, GStreamer already uses gnu-indent as a git commit hook to ensure that each commits passes gnu-indent rules before entering the git tree. We could do something similar to that, but using clang-format, which is way more powerful/flexible.
Yes, It's pretty messy. I think the original code used tab+2 spaces (it's a wierd combo that gnu uses I think). Trouble is that only I believe emac's and vim seem to support this format. almost any other text editor has serious problems with it. Do you have any good suggestions for a standard coding style (that's easy to use...) may as well keep discussion here.. My timezone is a bit odd (GMT+8) - so chat's always a bit hit/miss..
To be very honest, I don't care *too much* about coding style as long as we keep using the same one and I have a way to fix all my code and avoid spending time with coding style fixes. A while back when I was contributing to Firefox I remember that I could use whatever I wanted and at the end I invoke the clang-format tool I mentioned to format the patch. Lots of other big opensource projects use auto format tools to enforce coding style. Some have their own tool (like linux kernel and webkit), which would be overkill for us. Some others uses clang-format (like firefox). We could spend some time discussing which coding style is better and do not arrive to any conclusion or definition. Or, we could get one that it's already there. My suggestion is to get the one from Mozilla (https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style), add the .clang-format with the mozilla format (basically https://github.com/mozilla/gecko-dev/blob/master/.clang-format). That one uses spaces to indent. I've have been looking around and feels like indent-tabs are not being used by many big project anymore (despite linux kernel). I've added Richard to the discussion as well, as he's mentioned as one of the maintainers. However, I'm not sure if he's reading the emails... So, Alan, if you agree with that I can prepare a coding style document for us and a .clanf-format to auto format the code. Then, there's the big decision: Should we apply the format to all files right now? There's a good part of me that would love to do that. However, we will have to live with the fact that git blame won't be super useful anymore.
Created attachment 320341 [details] [review] huge formatting patch and adding clang-format tool
Most of the changes are indentation only, so git blame -w is still useful...
Created attachment 320388 [details] [review] huge commit with formater setup...
I'm fine with this, Sent an email to the seed mailing list... - If no-one else objects... Let's go with it on monday.
Could you apply this Alan? Thanks,
commited - we just had Chinese new year here... everything closed for a few days. Regards Alan