[webkit-dev] Is there a rule to use UNUSED_PARAM ?

Darin Adler darin at apple.com
Mon Oct 1 10:35:26 PDT 2012

I prefer we use UNUSED_PARAM as little as possible. The main reason is that we can utter UNUSED_PARAM and then use the parameter without getting a compiler error. This makes it easy to use the macro in a way that is misleading. It doesn’t actually enforce that a parameter is unused, and is more of a “compiler warning quieter” than a helpful building block.

Here are my proposed rules:

1) When possible, omit parameter names for unused parameters entirely.

2) When parameter names are critical for clarity, include the names, but commented out. This is one of the few cases where our coding guidelines should suggest commented-out code. And one of the few cases where we would suggest use of /* */ comments.

3) When a conditional written with #if means that a parameter is used only in certain cases, use UNUSED_PARAM for the other case. Try to keep these situations to a minimum by factoring functions out so that there are two complete separate function definitions rather than #if within a function. This can often be done quite elegantly with inline functions.

4) When a parameter is used only for an assertion, prefer ASSERT_UNUSED over UNUSED_PARAM. It has the same problem as UNUSED_PARAM that it gives no error if the parameter is actually used elsewhere in the function, but it has two benefits over UNUSED_PARAM: (1) Makes it clear that the parameter is used, and what it’s used for, since the assertion is there on that same line of code. (2) Name does not include the irritating abbreviation “param”.

-- Darin

More information about the webkit-dev mailing list