From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kgIEHGXyHGEBXwAAWB0awg (envelope-from ) for ; Wed, 18 Aug 2021 07:43:33 -0400 Received: by simark.ca (Postfix, from userid 112) id 5EBBC1EDFB; Wed, 18 Aug 2021 07:43:33 -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.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_REPLYTO_END_DIGIT,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 898DB1E4A3 for ; Wed, 18 Aug 2021 07:43:32 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C2554383582A for ; Wed, 18 Aug 2021 11:43:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2554383582A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1629287011; bh=YGpG5NnafF+TeMcldoW0qVch80gYrLwbWuLxFPVGLBA=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=OlhcC5u8t7UPCWVM82UEtemir7uIW7uXdPx9ck+PnQ3Oycpk0iky+wzBNUdeCP1X0 vIZBlLzgTltS8ZtM0nQnYeZPfFXuuht50TrU7fwgHWIv0o2Dacq3fzhePbHHx/xCGr eXa35CMkT80fDOoWkxPkQ6wiTi3DEHU+l/RZ0O4U= Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by sourceware.org (Postfix) with ESMTPS id 994313853C0F for ; Wed, 18 Aug 2021 11:43:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 994313853C0F Received: by mail-io1-xd32.google.com with SMTP id e186so2291711iof.12 for ; Wed, 18 Aug 2021 04:43:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YGpG5NnafF+TeMcldoW0qVch80gYrLwbWuLxFPVGLBA=; b=mdqKp9U0uwtq46KxLC2BqkmTjYLkN8v7TdgeS06h3kzI8zDKZGR2Zj68wEW/frXR4K DPoa7/Jzkm+jqFkv1M3+/n8+ZnfMUIYz7EtFaEGnqr2/6SxCfpkfz1eDfmL6shvltM0v vXVYhFXHVgXga5vIr6/AB+x1DoISfuCHBn7gpl3453jNVBHcgUdZGgFpXXzeNGkSn0aF BelJ9vxL3IJ3lYMdBnv1UuQ0tfxGvslrYoaogGLto4bGaX5uijF7sNawH1HDMlzqH0PZ /I+szjLDWRs+6XXMfJ0aQvt9s0hoKgRwvvKVof/hc92I3L3Op2DcWYr/Mj7JGdMBaLv0 Gdpw== X-Gm-Message-State: AOAM530d3Oh08aTtyUp+AYV9PurUlHV5WMUyaJ3xbZrF/f5qtN8rL6D8 FPBKVPM2C8bQmdgvF6LK9mZMcZLu72XWyx2E4xc= X-Google-Smtp-Source: ABdhPJxoopILzN/7sVU4E1QK2o1f2oL+EQ3+lbPPepbXf7JLqfJ/rUBjLrjbloXaF4Fx5NvfORH6uKnLqm2XAryymlc= X-Received: by 2002:a6b:6a14:: with SMTP id x20mr7048404iog.177.1629286991031; Wed, 18 Aug 2021 04:43:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 18 Aug 2021 14:43:00 +0300 Message-ID: Subject: Re: Coding standards proposal, usage of "this" To: Simon Marchi Content-Type: text/plain; charset="UTF-8" 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: , From: Ruslan Kabatsayev via Gdb-patches Reply-To: Ruslan Kabatsayev Cc: Simon Marchi via Gdb-patches Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On Mon, 16 Aug 2021 at 20:01, Simon Marchi via Gdb-patches wrote: > > >> - 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. > > > > I'm not really a fan of this, and I am also not aware of other > > projects using such a style. Since this makes calling member functions > > more verbose/uglier than calling free functions, this would also > > discourage member functions. Is there a need to distinguish these? > > There's no *need*, of course. It's just based on my experience, I > remember seeing some function calls, wondering how it could even work > with the passed arguments. And then I realized it was a method call, > where `this` is passed implicitly. > > Do you think it would discourage adding member functions, in opposition > to adding free functions? Or just leaving the code in-line, leading to > bigger methods? This will prevent the "prefer nonmember, nonfriends" mantra from working. Suppose you made a free function (so as to prevent accidental coupling to the private state of your class), and later it happens to need access to the state. This function is then turned into a (possibly const) method. And now... you have to alter all the callers to prefix the calls with `this->`, even though it's syntactically useless. Moreover, it may be easy to miss some, so unless there's a static analyzer checking for this rule, this leads to inconsistency. > > Simon