{"action":"created","issue":{"url":"https://api.github.com/repos/lefticus/cppbestpractices/issues/21","labels_url":"https://api.github.com/repos/lefticus/cppbestpractices/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/lefticus/cppbestpractices/issues/21/comments","events_url":"https://api.github.com/repos/lefticus/cppbestpractices/issues/21/events","html_url":"https://github.com/lefticus/cppbestpractices/issues/21","id":90999174,"number":21,"title":"best practice for getter","user":{"login":"sbowman-mitre","id":12277219,"avatar_url":"https://avatars.githubusercontent.com/u/12277219?v=3","gravatar_id":"","url":"https://api.github.com/users/sbowman-mitre","html_url":"https://github.com/sbowman-mitre","followers_url":"https://api.github.com/users/sbowman-mitre/followers","following_url":"https://api.github.com/users/sbowman-mitre/following{/other_user}","gists_url":"https://api.github.com/users/sbowman-mitre/gists{/gist_id}","starred_url":"https://api.github.com/users/sbowman-mitre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbowman-mitre/subscriptions","organizations_url":"https://api.github.com/users/sbowman-mitre/orgs","repos_url":"https://api.github.com/users/sbowman-mitre/repos","events_url":"https://api.github.com/users/sbowman-mitre/events{/privacy}","received_events_url":"https://api.github.com/users/sbowman-mitre/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-25T15:39:22Z","updated_at":"2015-06-25T19:59:12Z","closed_at":null,"body":"In the safety module, there is an example recommending using const to indicate an immutable getter method:\r\nstd::string get_value() const  { /* etc */ }\r\n\r\nHowever, I _think_ that best practices actually recommend going slightly further by also returning a const reference. Like this:\r\nstd::string const &get_value() const  { /* etc */ }\r\n\r\nCan anyone confirm or deny this practice? Is it a best practice?"},"comment":{"url":"https://api.github.com/repos/lefticus/cppbestpractices/issues/comments/115377270","html_url":"https://github.com/lefticus/cppbestpractices/issues/21#issuecomment-115377270","issue_url":"https://api.github.com/repos/lefticus/cppbestpractices/issues/21","id":115377270,"user":{"login":"Jofagi","id":6442817,"avatar_url":"https://avatars.githubusercontent.com/u/6442817?v=3","gravatar_id":"","url":"https://api.github.com/users/Jofagi","html_url":"https://github.com/Jofagi","followers_url":"https://api.github.com/users/Jofagi/followers","following_url":"https://api.github.com/users/Jofagi/following{/other_user}","gists_url":"https://api.github.com/users/Jofagi/gists{/gist_id}","starred_url":"https://api.github.com/users/Jofagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jofagi/subscriptions","organizations_url":"https://api.github.com/users/Jofagi/orgs","repos_url":"https://api.github.com/users/Jofagi/repos","events_url":"https://api.github.com/users/Jofagi/events{/privacy}","received_events_url":"https://api.github.com/users/Jofagi/received_events","type":"User","site_admin":false},"created_at":"2015-06-25T19:59:12Z","updated_at":"2015-06-25T19:59:12Z","body":"While it doesn't have the most upvotes, I find [this argument](http://stackoverflow.com/a/701398/27596) **against** const references pretty convincing: \r\nIt *potentially* gives better performance but the caller might store the result as a reference and this can lead to problems, when the original object goes out of scope. In my opinion, returning by value is fine most of the time."}}