Open 229c9cf0 opened 5 years ago
I've tried clang-format on the code base and it works, the trick is to set {SortIncludes: false}
as rearranging includes would break compilation. I've checked the generated assembly code on Linux and it is identical after formatting. I can generate some examples of using clang-format with different styles for comparison.
See this gist for c_init.c in different clang-format styles: https://gist.github.com/melvinzhang/def98589d85da808fe6034c6bad6a249
I won't try to defend any aspect of my terrible code formatting. Anything that makes it less terrible sounds good.
I would be happy to go through and clean up the indentation of files, but would like to ask if you prefer tabs or spaces @linleyh?
Great! Is there a more standard/popular approach to indentation these days? I'm happy either way.
I am unsure what others use (other than @melvinzhang suggested clang style), but I try to follow the Linux kernel development coding style. They use 8 character indentation, which they state "Rationale: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you’ve been looking at your screen for 20 straight hours, you’ll find it a lot easier to see how the indentation works if you have large indentations." Would like to get thoughts though.
If that's how the Linux kernel is indented, it's probably the way to go.
https://github.com/torvalds/linux/blob/master/.clang-format can be used to produce linux kernel style using clang-format. Unfortunately, clang-format is missing support for alignment of defines and initializers, see https://www.kernel.org/doc/html/latest/process/clang-format.html#missing-support
That should be okay - the code doesn't really have enough defines for that to be a problem, and I don't think it has any designated initialisers.
Indentation is completely broken right now. There's a weird mix of tabs and spaces, indentation depths differs, … It's bad enough that gcc is confused and (wrongly) complains about unguarded statements all over the place:
It's also really hard to read…
Could you fix this?
Alternatively, I could try to set up and run a code formatter on this and make a pull request – in which case, what should the indentation be?
grep|sed|sort|uniq
chain. (For me, single-space indentation is hard to read – with spaces, I'd suggest at least two per indentation level.)