220 26537 <nldt3m$onh$1@ger.gmane.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Woehlke <mwoehlke.floss@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Adding a const qualifier to class access modifiers
Date: Mon, 04 Jul 2016 10:50:30 -0400
Lines: 68
Approved: news@gmane.org
Message-ID: <nldt3m$onh$1@ger.gmane.org>
References: <7145a8aa-6a74-4ff3-8984-4a74aef66b5d@isocpp.org> <20160704042756.GA19918@noemi> <CAFk2RUaAW+xPzW5ov85qD0m9Dv6nikHZd0asUG7=2rinv3navg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-Trace: ger.gmane.org 1467643854 5595 80.91.229.3 (4 Jul 2016 14:50:54 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 4 Jul 2016 14:50:54 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC37LBFWUIFBBQ7P5G5QKGQE6LLWU4Q@isocpp.org Mon Jul 04 16:50:45 2016
Return-path: <std-proposals+bncBC37LBFWUIFBBQ7P5G5QKGQE6LLWU4Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wm0-f69.google.com ([74.125.82.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC37LBFWUIFBBQ7P5G5QKGQE6LLWU4Q@isocpp.org>)
	id 1bK5Cv-0005jy-Bb
	for gclcip-std-proposals@m.gmane.org; Mon, 04 Jul 2016 16:50:45 +0200
Original-Received: by mail-wm0-f69.google.com with SMTP id a66sf68723121wme.1
        for <gclcip-std-proposals@m.gmane.org>; Mon, 04 Jul 2016 07:50:45 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=to:from:subject:date:lines:message-id:references:mime-version
         :content-transfer-encoding:user-agent:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=oQeQ/uLEHmaQYbUVgxZN2LraeqLLXDKHtVnDkPRULlM=;
        b=rIoooOGtuslNKnAeDZDvPgaKB/3oiMZax+a4b85d+Pt9KNMh3KTC2hiZmu1s468AEj
         vX63JQXWp2YLNQTk5Ikj5ce7GYzoWHi/7Bp7h0mhHpE6j1kgDHIr+ptjnene8G5HnzZc
         3hyVVS12wUk4TCoGrhgDDvenrBQoJv+shbkW85ElZaIhYIT20U4GmE/h5BwIhSsVzcJV
         x06g7BSiwfDcwy/DE9hUT2udpmVwQ1pzvUVPQHflQ6xTLl12EU6B7UScECtvbIjGSnL0
         TSigR5+2OZ1VAoz5kPySPpmSYAuWmchY1u99d4GjAkOJe3BokqaGXn5mbg2h7S7LcESs 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:to:from:subject:date:lines:message-id:references
         :mime-version:content-transfer-encoding:user-agent:in-reply-to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=oQeQ/uLEHmaQYbUVgxZN2LraeqLLXDKHtVnDkPRULlM=;
        b=Xbz6zscHsdJVsMMwdl2cWS1sKIR5EIhbPPoIUUjV42X+M6sX/x3yPFwClT1bES1qhH
         ikR5+notojcwiucPAPrA1WdNzfmjSWWOb6mf8JACitUal3mcxu64YtRmOJNJ2LlGuFYC
         IxZOfKOKhVtk6Cj4rkLhLB6D3o7jhElbHDAL3/OM5w5lGh92V+Tk5d1RHsiiqgTZ/hNf
         IfH2VAx25hhWJVVAslOkGxr3l8x5MpHWlliUB05lB6HbZYd9A5YLdytuyzh8xFhAcnGz
         plVxdsmxIrK+H6nzZUcYQyBMPva81K1cDqAYXwFfd695ehMsEHGhrBy2PQ2PnvNS 
X-Gm-Message-State: ALyK8tKZAzCnvO5V0f4y8n3zGpMjhFn6ltTbwQHMnJfEU6PhoVSGisQx4AH1bg8A+SUBYQ==
X-Received: by 10.28.197.196 with SMTP id v187mr1846992wmf.3.1467643844684;
        Mon, 04 Jul 2016 07:50:44 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.46.33.74 with SMTP id h71ls150757ljh.45.gmail; Mon, 04 Jul
 2016 07:50:43 -0700 (PDT)
X-Received: by 10.25.168.202 with SMTP id r193mr3728695lfe.85.1467643843050;
        Mon, 04 Jul 2016 07:50:43 -0700 (PDT)
Original-Received: from plane.gmane.org (plane.gmane.org. [80.91.229.3])
        by mx.google.com with ESMTPS id u143si2095846lff.104.2016.07.04.07.50.42
        for <std-proposals@isocpp.org>
        (version=TLS1 cipher=AES128-SHA bits=128/128);
        Mon, 04 Jul 2016 07:50:42 -0700 (PDT)
Received-SPF: pass (google.com: domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as permitted sender) client-ip=80.91.229.3;
Original-Received: from list by plane.gmane.org with local (Exim 4.69)
	(envelope-from <gclcip-std-proposals@m.gmane.org>)
	id 1bK5Co-0005gQ-Q2
	for std-proposals@isocpp.org; Mon, 04 Jul 2016 16:50:39 +0200
Original-Received: from tripoint.kitware.com ([66.194.253.20])
        by main.gmane.org with esmtp (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Mon, 04 Jul 2016 16:50:38 +0200
Original-Received: from mwoehlke.floss by tripoint.kitware.com with local (Gmexim 0.1 (Debian))
        id 1AlnuQ-0007hv-00
        for <std-proposals@isocpp.org>; Mon, 04 Jul 2016 16:50:38 +0200
X-Injected-Via-Gmane: http://gmane.org/
Original-Lines: 49
Original-X-Complaints-To: usenet@ger.gmane.org
X-Gmane-NNTP-Posting-Host: tripoint.kitware.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
In-Reply-To: <CAFk2RUaAW+xPzW5ov85qD0m9Dv6nikHZd0asUG7=2rinv3navg@mail.gmail.com>
X-Original-Sender: mwoehlke.floss@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of gclcip-std-proposals@m.gmane.org designates 80.91.229.3 as
 permitted sender) smtp.mailfrom=gclcip-std-proposals@m.gmane.org;
       dmarc=fail (p=NONE dis=NONE) header.from=gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:26537
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26537>

On 2016-07-04 05:52, Ville Voutilainen wrote:
> On 4 July 2016 at 07:27, Magnus Fromreide <magfr@lysator.liu.se> wrote:
>> On Sun, Jul 03, 2016 at 06:25:42PM -0700, =C3=93lafur Waage wrote:
>>> One of the biggest things I have seen in developing medium to large sca=
le
>>> systems is how useful const is to show the original author's intent, th=
at
>>> this value should not be changed, even by grabbing a mutable variable a=
nd
>>> creating a const auto& temporary and using that temporary to state that
>>> this value should stay the same.
>>>
>>> This get's tricky when dealing with class members, especially when
>>> accessing them from the outside.
>>>
>>> Should you limit access via private and provide a Get function?
>>> - Writing all those Get type functions can get tiring and bloats the cl=
ass
>>> with very trivial functions, even if they return a copy or a const ref.
>>>
>>> Should you keep it public and take the python stance of "we're all adul=
ts
>>> here"?
>>> - Opening the access to anyone outside can later down the line introduc=
e
>>> errors if it's a value that needs to be updated in a certain way to kee=
p
>>> the internal state of the class sane.
>>
>> The usual reply to this question is neither.
>>
>> What you should do is move the logic that need to access the value into
>> methods of the class so that the class becomes more self contained.
>> Yes, I am aware of this beeing harder to but the resulting system is gen=
erally
>> easier to understand since there is less coupling between different clas=
ses.
>=20
> With NDSMIs, this is what I'd do:
>=20
> class X
> {
>     string data;
> public:
>     const string& cdata =3D data;
> };
>=20
> I don't think the suggested problem is so common that we need to
> invent a new kind of an access specifier
> to cater for it.

Actually, properties would be great here; provide a public get but no
set. The problem with the above is that it increases the size of the
class. The most recent iteration of "properties", involving inner
classes and zero-size members, would solve this.

--=20
Matthew

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/nldt3m%24onh%241%40ger.gmane.org.

.
