CODING_CONVENTIONS: Add reference to IS_ACTIVE and IS_USED macros#12781
Conversation
|
There was a board consensus on the PR that added @cgundogan, @smlng, @jia200x, @benpicco, @waehlisch: A few more ACKs would be nice here, even though this addition is pretty much the logical consequence of the discussion in #12626 |
|
Maybe some stronger wording would be nice: "The code should only contain |
|
Can we talk about consequences of merging this for a bit? Say there is an older PR with a few thousand lines of code containing a few |
I'd say yes. Applying this only to a subset of PRs will only confuse everyone. And the motivation to clean things up after merging is often not as high as before merging ;-) But I totally agree that a situation like that can be frustrating. However, better code maintainability can also avoid a lot of frustration later on. |
If those guidelines are getting interpreted as legal binding documents (which I see happening) I wonder if they end up doing more harm than good. Before this turns into a game of Nomic, let's add a statement that those are guidelines and common sense / maintainer judgement should still apply. |
That's what I'm wondering: does the code really become more maintainable if I write if (USED(GNRC_IPV6) {
/* do something */
}instead of #ifdef MODULE_GNRC_IPV6
/* do something */
#endif? |
Doesn't help... The maintainer guidelines were also often misinterpreted as a bible in the past :-P. |
The current wording is "In order to follow Linux's recommendation [...]". That is not that binding. |
I don't think so. Especially considering that the macro cannot be used everywhere. |
In no cases it will get less maintainable, but in many cases it will become more maintainable. E.g. the compiler will verify the syntax of all code flavors and generate warnings for all code flavors if they are visible to the compiler. A But obviously not every Summing up: It has some advantages and no disadvantages. That is a pretty easy decision to me. |
Yes but you write
I mean it doesn't hurt to suggest a change if it makes the code more readable, but this shouldn't be a requirement that is enforced no matter if it makes sense for that particular section of code or not. So the wording of this PR is fine. It's an option that can be used to make the code more readable, just because this option exists doesn't mean we must stomp out all |
This is somewhat of a contradiction 😕 but I get what you mean
Don't get me wrong: I'm always in favor of making the compiler spot things it usually wouldn't find! What I want to prevent is bugging contributors (especially those waiting patiently for ages to get their PR finally in) with such details especially if their tests might already cover the "blinded compiler" problem already (e.g. when I use |
We'll, to me a coding convetion is not about providing tools, but consistency. E.g. I really like smart tabs for indent. I also prefer the Linux kernel coding convention in regard to But obviously, there are always cases when the coding convention cannot be reasonably applied. E.g. blindly enforcing the 80 chars limit everywhere is going to be headache. In some cases this just reduces the readability quite significantly. And the case of replacing How about adding an amendment for common sense in general: #12785. This could also be cited in discussions later on ;-) But honestly: The time and effort required to update existing PRs to use |
|
Again, I'm not arguing for softening the coding conventions. I just have a very bad feeling with enforcing a recently added feature via the coding convention. |
OK, count me convinced. How about just letting this unspecified and let the reviewer decide whether it would be beneficial and not to frustrating to apply it for old PR? |
waehlisch
left a comment
There was a problem hiding this comment.
@miri64, as far as i understand you, your question is independent of the current PR. does a change in the Coding Conventions imply that all open PRs need to be updated? this is a valid question but not specific to this PR. personally, i'm fine not to stress existing PRs.
In this case it is dependent of this PR, IMHO. This PR updates the coding conventions—which some maintainers enforce more rigorously than others—with a guideline to prefer a feature that was proposed and merged quite recently (#12626 was opened on Nov 1st and merged on Nov 11th) over the current state of the art (that is based on a more common C-based approach). But I agree that my concerned should not block this PR, just be taken into account when reviewing older PRs (that's why I didn't put a change request on this PR in the first place ;-)). |
|
not sure about your argumentation @miri64. that a feature was merged recently, might lead to lower adaption compared to features that exist since ages. still, as long as usage is not enforced via the Coding Conventions, you cannot assume that developers use it. ... and again, your concerns don't relate specifically to this feature but to all changes that refer to recently introduced features. anyhow, seems that we have consensus to merge and close, right? |
I am not against using this feature for newer PR and applying its usage for code already in master. I am however against bugging contributors of long open PRs about this (unless the PR stays open even longer). And yes, this is also related to potential other additions to the coding conventions, but was caused by this PR.
Yes. |
we already agreed on this ;). |
I dissociate myself from my previous statement. If that gets interpreted as "documentation is needed for every I'm still in favor to default to the c-style conditional, though. |
|
For the record, I don't like this, I'm not gonna use this in code I write. And I'm not thrilled to see members of the community that don't write, read or review code to weigh in on decisions like this. |
|
@kaspar030, i was asked to articulate my opinion. i did. the PR is a low brainer, even for me. Except you, @kaspar030, and me, i count four people who don't object the PR. |
cgundogan
left a comment
There was a problem hiding this comment.
We thoroughly discussed advantages and drawbacks in #12626 with an outcome to favour c-style conditionals instead of a preprocessor-based conditional compilation. IS_ACTIVE and IS_USED support a cleaner way of expressing conditionals. So, also ACK from my side for this amendment to the coding conventions.
|
Ok, 3 ACKs and rough consensus. Let's get this one merged. |
Contribution description
According to the discussion in #12626, there was a common agreement on reducing the use of C preprocessor conditionals in favor of C conditionals, where possible. This is actually mentioned in the Linux coding conventions.
This PR adds a reference to the
IS_USEDandIS_ACTIVEmacros introduced by #12626, as means to follow this recommendation. Also a link to this particular section in Linux's coding convention is added, where the rationale behind this is explained in detailed. I think it doesn't make much sense to repeat what's already explained there.Testing procedure
Read the document, check the links.
Issues/PRs references
#12626