From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oAQnIBiGFmFFGAAAWB0awg (envelope-from ) for ; Fri, 13 Aug 2021 10:47:52 -0400 Received: by simark.ca (Postfix, from userid 112) id 7FD6D1EDFB; Fri, 13 Aug 2021 10:47:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C63201E4A3 for ; Fri, 13 Aug 2021 10:47:51 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DEC83969C04 for ; Fri, 13 Aug 2021 14:47:51 +0000 (GMT) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id DDB373858023 for ; Fri, 13 Aug 2021 14:47:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DDB373858023 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x435.google.com with SMTP id f5so13596414wrm.13 for ; Fri, 13 Aug 2021 07:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=C169Xk/3Mhhfs76j/CqElYop9EtyUDmGXm2CZD8v9LQ=; b=RVzebKxPGwlFlTBodX9PIAZ4zIN5+dBlDlNLNjjLf1lzW0N61Bdzzx7nYX5m2JVCGy 0M2LWtPUssrtReOa1VLioR5jOhQFsoB1SrO6+PBIjkkwmDGyh0m6iiN+Y9p/U+k+nwCd 8F50jmW4Ivu8Z92iAp+N6ra271STzgkKFMSjNrRhXitH3N4lQ0/xAPm97I0PCPjjhLek 6wrRoZC7mtU6t46rP31HIrGvg6WwxPMWEalyvMLERJZSrEtCLnmNBKZyPMIvpFHaVsiL 6K7D2RR4gDYIkEvcratvXsXLVw6SkiDW46etgI/G0Jy5tqHrCud6ZiG4cUOhH6pAJWVp zpXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=C169Xk/3Mhhfs76j/CqElYop9EtyUDmGXm2CZD8v9LQ=; b=Q1rKlmHrK1VMnQOYbmBHOZ1iKxrJov4MWy6FAojjuplhBZKTk/Gswf+H1Hk+urYMvS IWJ5I0itZScTu/QDaRXOAgNBR/ngyv+0DHjSR/zIU9FOfALAG/65AVAAoSHh2x0F+9R6 o9GFbSrgh5kcSwaYwTJDQ8OvWthMBKcK4puXEC1FD4ODp0wPKk/iLuBTCMzKlS92+Hyo QwXi2vaP33LvTR9RM5GHLHZYtmmq0fSgkNigsw2l0LWenJbkMeytkS+DwE8moOBHgaHL ++pzsIhAyTgun1Ih7yXvxSMWGLYtgiUbXBmNC4OywXzFp/Vm2tE5jRbZBxL1mltyMjOD 9agg== X-Gm-Message-State: AOAM530OdiF79kZ9EE4b4fJyFJS3bRp1uEIjpO87BdSR4CBak5wAZDXX n9I/CKdmOlChNyivtaKc7xxTTg== X-Google-Smtp-Source: ABdhPJz6E4o78TVkqDKmTTKNxnE4WufZeMoV9tRFrTXYM6h2YbB41hZNW3YcBZUfFLAgAKI/yv07Og== X-Received: by 2002:adf:f141:: with SMTP id y1mr3602632wro.173.1628866049651; Fri, 13 Aug 2021 07:47:29 -0700 (PDT) Received: from localhost (host86-175-180-250.range86-175.btcentralplus.com. [86.175.180.250]) by smtp.gmail.com with ESMTPSA id i21sm1835275wrb.62.2021.08.13.07.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Aug 2021 07:47:29 -0700 (PDT) Date: Fri, 13 Aug 2021 15:47:28 +0100 From: Andrew Burgess To: Simon Marchi Subject: Re: Coding standards proposal, usage of "this" Message-ID: <20210813144728.GL462163@embecosm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 15:45:04 up 11 days, 20:25, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" * Simon Marchi via Gdb-patches [2021-08-13 10:26:48 -0400]: > Hi all, > > Here's something I had in mind for a while. We don't consistently use > `this` when referring to fields or methods of the current object. I > never now if I should use it or not, or point it out in review. I > therefore propose these rules so that we have something to refer to. > > - Use `this` when referring to a data member that is not prefixed by > `m_`. Rationale: without `this`, it's not clear that you are > referring to a member of the current class, versus a local or global > variable. > - Don't use `this` when referring to a data member that is prefixed by > `m_`. Rationale: the prefix already makes it clear that you are > referring to a member of the current class, so adding `this` would > just add noise. > - Use `this` when referring to a method of the current class. > Rationale: without `this, it's not clear that you are referring to a > method of the current class, versus a free function. > > If we had a convention for how to name internal helper methods, which > would make it clear that they are methods of the current object and not > free functions (a bit like `m_` does for data members), we could omit > `this` when calling such a method. But we don't have that at the > moment. I'd be OK with extending the use of the m_ prefix for private member functions. But that wouldn't change the above rules, which all make sense to me. Thanks, Andrew > > A concrete example: > > int a_global; > > struct a_struct > { > int a_method () > { > int a_local = 17; > > return (a_local > + a_global > + m_a_private_field > + this->a_public_field > + this->a_helper_method ()); > } > > int a_public_field; > > private: > int a_helper_method () > { > return m_a_private_field; > } > > int m_a_private_field; > }; > > Any comments? My intention would be to add this to the coding standards > on the wiki. > > Simon