Skip to content

Style discussion #498

@Sazerac4

Description

@Sazerac4

I created this issue to centralize discussions about code style (solution and problems). I took some comments from the last PR :

I am not sure about the best way to handle that. Any proposals?

The problem is mixing preprocessor directives indenting with statements (if, for, switch, ...) indenting that might yield very misleading looking code when preprocessor is heavy used with code.
example:

void foo(void) {
#if TEST1 == 0
	#if TEST2 == 0
		if (true) {  // This if is on the wrong indentation
	#endif
#endif
		for (int i = 0; i < 10; ++i) {
			// do something
		}
#if TEST1 == 0
	#if TEST2 == 0
		}  // This brace is on the wrong indentation
	#endif
#endif
}

I think we can reverse the logic, set IndentPPDirectives: None and add manual indentation when it is pertinent with clang-format off.
Edit: It might be worth it. Most styles do not indent directives.

Edit: Maybe reordering the code that way, that only one code segment needs to be excluded from auto formatting.

I think you shouldn't code based on formatter (most of the time). We add unnecessary complexity when programming


@rokath
Maybe we keep the trice8|16|32|64.c|h files inside .clang-format-ignore. These files would loose readability for my taste when re-formatted with IndentPPDirectives: None. But I have no strong opinion on this because they then formatted differently to trice.c|h. On trice.c|h I agree to drop the pre-processor macros indent.
Edit: https://stackoverflow.com/questions/2975330/how-do-you-indent-preprocessor-statements

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions