220 26532 <20160704042756.GA19918@noemi> article
Path: news.gmane.org!not-for-mail
From: Magnus Fromreide <magfr@lysator.liu.se>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Adding a const qualifier to class access modifiers
Date: Mon, 4 Jul 2016 06:27:56 +0200
Lines: 48
Approved: news@gmane.org
Message-ID: <20160704042756.GA19918@noemi>
References: <7145a8aa-6a74-4ff3-8984-4a74aef66b5d@isocpp.org>
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 1467606490 21897 80.91.229.3 (4 Jul 2016 04:28:10 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 4 Jul 2016 04:28:10 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDELLREETMBRBT6L465QKGQEZNYNIBA@isocpp.org Mon Jul 04 06:28:01 2016
Return-path: <std-proposals+bncBDELLREETMBRBT6L465QKGQEZNYNIBA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wm0-f71.google.com ([74.125.82.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDELLREETMBRBT6L465QKGQEZNYNIBA@isocpp.org>)
	id 1bJvUG-0000jh-Ds
	for gclcip-std-proposals@m.gmane.org; Mon, 04 Jul 2016 06:28:00 +0200
Original-Received: by mail-wm0-f71.google.com with SMTP id a66sf57405181wme.1
        for <gclcip-std-proposals@m.gmane.org>; Sun, 03 Jul 2016 21:28:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:subject:message-id:mail-followup-to:references
         :mime-version:content-disposition:content-transfer-encoding
         :in-reply-to:user-agent: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=IzVU3tyI145LY583wrtlI0CJTX4YYnZgD2MwMd/X/LA=;
        b=ukPev/2/c8RWFnqYsKvb2ZF/VPjmWg5ZzjUTK4eYfm8yk/17uTIxvCDnUlkRu0S5w0
         Uoum7kW2/621Ub2Dtfmupexcn7jJVMnSAiz1doXqZ/hM4YsZtzWssjaKYLFJJZF9bUSe
         H7afCua6CW6x0XJHl2PgpYmsHIAOL3E72sCYK8D+QBUiWj29kN15EHQZNsv9NZslDH9h
         pbC/Bgw11Zr2VVTZAYFjiPCzpjm+ItX5gxelNTFmohMvDdH4YMBhGFIsK7H14O0B7Mgx
         wk4ZULzTD9+ZHp++noukfypL17c 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to
         :references:mime-version:content-disposition
         :content-transfer-encoding:in-reply-to:user-agent: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=IzVU3tyI145LY583wrtlI0CJTX4YYnZgD2MwMd/X/LA=;
        b=O8kwA24JnbfZy7UswKwm8ETmVmGOnlKo8Tr8HijliVT/2Jqo9UhRpkYZfDFIFqQKtv
         X8hd5d+NNZEkNzXOUXXwwrGIF7XIrZRq4rVyNq87LXSE2LEYkFpqSt1TcIPqNEJD8snL
         IoL5bAe6AWe3jy0JOrqxFabscr+WNcvU2G9CGP2dzozXtbYlLNChZGHXrcOyRF4dukoT
         45YhrvIQIHFHjuEUlO+oLxs/sg8+CKn2DyCnhuxNuq+hKff0pvFyIodDavsT6DJfwyce
         6wrPPE7x28M0XTokjM4Rpen 
X-Gm-Message-State: ALyK8tLoie6pcNg7mkZrgIv26BMM40QIu4QdaafouOOTpb6rXLVlHHQPEiGwRvAx+2Ji+Q==
X-Received: by 10.46.33.169 with SMTP id h41mr5461724lji.7.1467606479954;
        Sun, 03 Jul 2016 21:27:59 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.46.1.106 with SMTP id 103ls134829ljb.31.gmail; Sun, 03 Jul
 2016 21:27:58 -0700 (PDT)
X-Received: by 10.25.219.141 with SMTP id t13mr1805835lfi.62.1467606478710;
        Sun, 03 Jul 2016 21:27:58 -0700 (PDT)
Original-Received: from mail.lysator.liu.se (mail.lysator.liu.se. [130.236.254.3])
        by mx.google.com with ESMTPS id a18si1556191lfb.89.2016.07.03.21.27.58
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 03 Jul 2016 21:27:58 -0700 (PDT)
Received-SPF: pass (google.com: domain of magfr@lysator.liu.se designates 130.236.254.3 as permitted sender) client-ip=130.236.254.3;
Original-Received: from mail.lysator.liu.se (localhost [127.0.0.1])
	by mail.lysator.liu.se (Postfix) with ESMTP id 53B574000B
	for <std-proposals@isocpp.org>; Mon,  4 Jul 2016 06:27:58 +0200 (CEST)
Original-Received: from noemi (h-176-10-249-241.na.cust.bahnhof.se [176.10.249.241])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by mail.lysator.liu.se (Postfix) with ESMTPSA id 1D4C740005
	for <std-proposals@isocpp.org>; Mon,  4 Jul 2016 06:27:58 +0200 (CEST)
Mail-Followup-To: std-proposals@isocpp.org
Content-Disposition: inline
In-Reply-To: <7145a8aa-6a74-4ff3-8984-4a74aef66b5d@isocpp.org>
User-Agent: Mutt/1.6.1 (2016-04-27)
X-Virus-Scanned: ClamAV using ClamSMTP
X-Original-Sender: magfr@lysator.liu.se
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of magfr@lysator.liu.se designates 130.236.254.3 as permitted sender) smtp.mailfrom=magfr@lysator.liu.se
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:26532
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/26532>

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 scale=
=20
> systems is how useful const is to show the original author's intent, that=
=20
> this value should not be changed, even by grabbing a mutable variable and=
=20
> creating a const auto& temporary and using that temporary to state that=
=20
> this value should stay the same.
>=20
> This get's tricky when dealing with class members, especially when=20
> accessing them from the outside.
>=20
> Should you limit access via private and provide a Get function?
> - Writing all those Get type functions can get tiring and bloats the clas=
s=20
> with very trivial functions, even if they return a copy or a const ref.
>=20
> Should you keep it public and take the python stance of "we're all adults=
=20
> here"?
> - Opening the access to anyone outside can later down the line introduce=
=20
> errors if it's a value that needs to be updated in a certain way to keep=
=20
> 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 genera=
lly
easier to understand since there is less coupling between different classes=
..

/MF

--=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/20160704042756.GA19918%40noemi.

.
