[webkit-dev] Style proposal for branch style for macros

Mark Rowe mrowe at apple.com
Sun Apr 20 14:43:54 PDT 2014


On Apr 20, 2014, at 14:02, Filip Pizlo <fpizlo at apple.com> wrote:

> The #if means that the code being guarded isn't indented. I believe that indenting control flow is a good idea. 
> 
> Also, using normal if's whenever it would compile and be semantically equivalent means that the code being protected would benefit from syntax/type/semantic checking even in a release build.

We use preprocessor defines to distinguish between many things besides debug and release builds, and in many cases it’s impossible to tell ahead of time whether the alternate paths will compile on all platforms. This is particularly true for code guarded by defines related to the compiler, target platform, or OS version, but is also a concern with feature defines where symbols have been #if’d out.

> I think of this as being analogous to our preference for static assertions: we use them whenever we can but resort to dynamic assertions when we can't. 

I don’t think this is a great analogy. It’s usually clear from the context whether what you’re asserting is a compile-time or run-time concept, and thus whether a compile-time or run-time assertion is appropriate. It’s far from obvious whether all branches of an if will compile.

- Mark



More information about the webkit-dev mailing list