[riot-devel] Coding-conventions: astyle

Oleg Hahm oliver.hahm at inria.fr
Tue Jun 18 18:54:05 CEST 2013


Hi Christian!

> I created a astylerc for automated coding style fixing.
Thanks for your effort!

> After running this we have a lot changes:
> 209 files changed, 15148 insertions(+), 12980 deletions(-)
> 
> but the code is more readable and maintainable....
That's the general idea behind the coding conventions. ;-) However, in some
(rare) cases it might be beneficial not to stick too the coding conventions
too literal.

For example core/bitarithm.c

The current code is:
    r =     (v > 0xFFFF) << 4; v >>= r;
    shift = (v > 0xFF  ) << 3; v >>= shift; r |= shift;
    shift = (v > 0xF   ) << 2; v >>= shift; r |= shift;
    shift = (v > 0x3   ) << 1; v >>= shift; r |= shift;
                                            r |= (v >> 1);

astyle would convert it into:
    r = (v > 0xFFFF) << 4;
    v >>= r;
    shift = (v > 0xFF) << 3;
    v >>= shift;
    r |= shift;
    shift = (v > 0xF) << 2;
    v >>= shift;
    r |= shift;
    shift = (v > 0x3) << 1;
    v >>= shift;
    r |= shift;
    r |= (v >> 1);

In this case I would definitely prefer the non-cc (aka the current) version.

> I can also create a pre commit hook to ensure this style!
In fact, a nice idea. I'm not an expert on git commit hooks. Is it possible to
configure these hooks in an optional manner? Or is there any way to declare
exceptions from the coding conventions for particular pieces within the code?

Anyway, I will browse through the entire suggestions of astyle and probably
apply most of the changes to the repository.

Cheers,
Oleg
-- 
# Okay, what on Earth is this one supposed to be used for?
        linux-2.4.0/drivers/char/cp437.uni


More information about the devel mailing list