Return-Path: X-Original-To: apmail-mesos-dev-archive@www.apache.org Delivered-To: apmail-mesos-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 252AF18DF1 for ; Thu, 5 Nov 2015 05:36:21 +0000 (UTC) Received: (qmail 960 invoked by uid 500); 5 Nov 2015 05:36:20 -0000 Delivered-To: apmail-mesos-dev-archive@mesos.apache.org Received: (qmail 880 invoked by uid 500); 5 Nov 2015 05:36:20 -0000 Mailing-List: contact dev-help@mesos.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mesos.apache.org Delivered-To: mailing list dev@mesos.apache.org Received: (qmail 868 invoked by uid 99); 5 Nov 2015 05:36:20 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Nov 2015 05:36:20 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id D5D2BC0FF0 for ; Thu, 5 Nov 2015 05:36:19 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.1 X-Spam-Level: X-Spam-Status: No, score=-0.1 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id HVqwj0a98ZcL for ; Thu, 5 Nov 2015 05:36:04 +0000 (UTC) Received: from mail-yk0-f169.google.com (mail-yk0-f169.google.com [209.85.160.169]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 6F3B923067 for ; Thu, 5 Nov 2015 05:36:04 +0000 (UTC) Received: by ykdv3 with SMTP id v3so23603410ykd.0 for ; Wed, 04 Nov 2015 21:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=u1RgmCVYumY9rRVGv2I1H/wt0vubYuaDc8C1RsmP2Kc=; b=gveJ4rvo/R4QOnxWxYLQ+e+tD4E39FWNkjbwwBmRfsj8lRkM8SdYeFnqeBuOyQAoQU CIZpdUmDMPsy8tsR/Mf5sis8vh2TZkXYBtxWJslKT23phSUy0LSh2Ixv4zNguyVkSc6p rSijWX+eJc6KYH04a8XCiUsOs6t+x7nDoLCOidlcbotyKOOenKJ4Wyg65M/z5xYS9v9k zH8SJ23n1i4tzcTtUbO76M/Qy9fB6yCU96iDYTsgfxOVONgKO/z0wKxY46ktk7jo1Rpa n49KDRXSHwvDPY6sQLr0L/XfrgcKIBpJ75Xb+7VNa4uYJfNucaVOgfhu4TgIiQOwBLj/ GouA== MIME-Version: 1.0 X-Received: by 10.129.85.84 with SMTP id j81mr4596492ywb.194.1446701763538; Wed, 04 Nov 2015 21:36:03 -0800 (PST) Received: by 10.13.204.88 with HTTP; Wed, 4 Nov 2015 21:36:03 -0800 (PST) Date: Wed, 4 Nov 2015 21:36:03 -0800 Message-ID: Subject: Proposal: move towards #pragma and away from #include guards From: Alex Clemmer To: dev Content-Type: text/plain; charset=UTF-8 Hey folks. In r/39803[1], Mike Hopcroft (in quintessential MSFT style, heh) brought up the issue of moving away from #include guards and towards `#pragma once`. As this has been brought up before, I will be brief: we think it's revisiting because the primary objection in previous threads appears to be that, though `#pragma once` is a cleaner solution to the multiple-include problem, it's not so much better that it's worth the code churn. However, the ongoing Windows integration work means we have to touch these files anyway, so if we agree this is cleaner and desirable, then this is an opportunity to obtain that additional code clarity, without the cost of the churn. For the remainder of the email, I will summarize the history of our discussion of this issue, who will do the work, and what the next steps are. PROPOSAL: We propose that all new code use `#pragma once` instead of #include guards; for existing files, we propose that you change #include guards when you touch them. HISTORY: This has been discussed before, most recently a year ago on the mailing list[2]. There is a relevant JIRA[3] and discarded review[4] that changes style guide's recommendation on the matter. SUMMARIZED OBJECTIONS: 1. The Google style guide explicitly forbids `#pragma once`. 2. This results in a lot of code churn, but is only marginally better. 3. It's not C++ standardized/it's platform dependent/IBM's compiler doesn't support it. 4. Popular projects like Chrome don't do `#pragma once` because of history clutter. 5. Intermediate state of inconsistency as we transition to `#pragma once` from #include guards. OUR RESPONSE: Objections (1), (2), and (4) are essentially the same -- Dominic Hamon points out in a previous thread that the Google style guide was canonized when `#pragma once` was Windows-only, and the guidance has not changed since because of the history churn problem. As noted above, we think the history churn problem is minimized by the fact that it can be wrapped up into the Windows integration work. For objection (3), the consensus seems to be that the vast majority of compilers we care about (in particular, the ones supporting C++ 11) do support it. For objection (5) we believe the inconsistent state is likely to not be long lived, as long as we commit to wrapping this work up into the Windows integration work. SUMMARIZED ADVANTAGES: * Basically fool-proof. Communicates simply what its function is (you include this file once). Semantically it is "the right tool for the job". * No need for namespacing conventions for #include guards. * No conflicts with reserved identifiers[5]. * No internal conflicts between include guards in Stout, Process library, and Mesos (this is one reason we need the namespacing conventions) * Reduces preprocessor definition clutter (we should rely on #define as little as humanly possible). * Optimized to be easy to read and reason about. NEXT STEPS: If we agree that this is the right thing to do, committers would ask people to use `#pragma once` for new code when presented in code reviews. For files that exist, I will take point on transitioning as we complete the Windows integration work. I expect this work to completely land before the new year. Thanks, [1] https://reviews.apache.org/r/39803/ [2] https://www.marc.info/?t=142540100400015&r=1&w=2 [3] https://issues.apache.org/jira/browse/MESOS-2211 [4] https://reviews.apache.org/r/30100/ [5] http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier -- Alex Theory is the first term in the Taylor series of practice. -- Thomas M Cover (1992)