{"action":"created","issue":{"url":"https://api.github.com/repos/ckeditor/ckeditor5-design/issues/88","labels_url":"https://api.github.com/repos/ckeditor/ckeditor5-design/issues/88/labels{/name}","comments_url":"https://api.github.com/repos/ckeditor/ckeditor5-design/issues/88/comments","events_url":"https://api.github.com/repos/ckeditor/ckeditor5-design/issues/88/events","html_url":"https://github.com/ckeditor/ckeditor5-design/issues/88","id":115315824,"number":88,"title":"Rich getters and setters vs. methods","user":{"login":"Reinmar","id":156149,"avatar_url":"https://avatars.githubusercontent.com/u/156149?v=3","gravatar_id":"","url":"https://api.github.com/users/Reinmar","html_url":"https://github.com/Reinmar","followers_url":"https://api.github.com/users/Reinmar/followers","following_url":"https://api.github.com/users/Reinmar/following{/other_user}","gists_url":"https://api.github.com/users/Reinmar/gists{/gist_id}","starred_url":"https://api.github.com/users/Reinmar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Reinmar/subscriptions","organizations_url":"https://api.github.com/users/Reinmar/orgs","repos_url":"https://api.github.com/users/Reinmar/repos","events_url":"https://api.github.com/users/Reinmar/events{/privacy}","received_events_url":"https://api.github.com/users/Reinmar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ckeditor/ckeditor5-design/labels/code%20style","name":"code style","color":"006b75"},{"url":"https://api.github.com/repos/ckeditor/ckeditor5-design/labels/es6+","name":"es6+","color":"006b75"},{"url":"https://api.github.com/repos/ckeditor/ckeditor5-design/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-11-05T16:05:56Z","updated_at":"2015-11-26T10:53:59Z","closed_at":null,"body":"Naming clarification: \r\n\r\n```\r\nclass Foo {\r\n    get y() {\r\n        // getter\r\n    }\r\n \r\n    getX() {\r\n        // method\r\n    }\r\n}\r\n```\r\n\r\nThe problem is how complex getters (mainly) and setters we can produce. Can every piece of code which is not an action (which does not modify some state) but only returns some value be a getter? Or, based on its complexity or \"range of interest\" at some point it should become a `getSth()` method?\r\n\r\nLet's consider a `Node` class. Between its properties it has things like a `parent`, `childCount`, `index`, `path` (array of ancestors indexes), etc. While it's clear that `parent` and `childCount` can be getters, because they are super simple:\r\n\r\n```\r\nget childCount() {\r\n    return this._children.length;\r\n}\r\n```\r\n\r\nIt's not that clear choice when it comes to `index` and `path`. Their complexity is much higher and they access other instances' properties. At the same time it's clear that they are not actions and in some super optimised optimisations they could be even cached inside that specific node. So should they be getters or methods?\r\n\r\nWe tried to find some rule of thumb and we were considering:\r\n\r\n1. estimating their complexity (I think it's an overkill especially if you have to estimate native methods' complexity :D),\r\n2. agreeing that a getter should not access other instances' (of any class – even the same) properties,\r\n3. agreeing to produce very complex getters and setters.\r\n\r\nI'm personally hesitating between 2. and 3."},"comment":{"url":"https://api.github.com/repos/ckeditor/ckeditor5-design/issues/comments/159877952","html_url":"https://github.com/ckeditor/ckeditor5-design/issues/88#issuecomment-159877952","issue_url":"https://api.github.com/repos/ckeditor/ckeditor5-design/issues/88","id":159877952,"user":{"login":"pjasiun","id":1166967,"avatar_url":"https://avatars.githubusercontent.com/u/1166967?v=3","gravatar_id":"","url":"https://api.github.com/users/pjasiun","html_url":"https://github.com/pjasiun","followers_url":"https://api.github.com/users/pjasiun/followers","following_url":"https://api.github.com/users/pjasiun/following{/other_user}","gists_url":"https://api.github.com/users/pjasiun/gists{/gist_id}","starred_url":"https://api.github.com/users/pjasiun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pjasiun/subscriptions","organizations_url":"https://api.github.com/users/pjasiun/orgs","repos_url":"https://api.github.com/users/pjasiun/repos","events_url":"https://api.github.com/users/pjasiun/events{/privacy}","received_events_url":"https://api.github.com/users/pjasiun/received_events","type":"User","site_admin":false},"created_at":"2015-11-26T10:53:59Z","updated_at":"2015-11-26T10:53:59Z","body":"About the `get  hashedValue` I am not sure it should be a getter. It may have small complexity now, but are you sure you will not you more complex algorithm in the future? What them? Should we mark getter as a deprecated and introduce `getHashedValue`? We are working on the code which should live next 5-10 (no one wants to rewrite plugins every year), so this may be a problem in the future. This is I think that in many cases we should avoid using getters, even though they are cool ;)"}}