{"issue":{"state":"open","created_at":"2011-11-21T04:34:59Z","updated_at":"2011-11-21T16:49:13Z","user":{"gravatar_id":"8672f1c3b11cc7390ec341ac25d7e88e","id":579974,"url":"https://api.github.com/users/gavinking","login":"gavinking","avatar_url":"https://secure.gravatar.com/avatar/8672f1c3b11cc7390ec341ac25d7e88e?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":4,"body":"So I think it's fair to observe that the response to our visibility model has been a bit mixed. Now, I'm sure we could put a lot of that down to the fact that it's something different, and whenever something is different to what people are used to, some people are going to dislike it until they get used to it.\r\n\r\nStill, as much as I think this is a much better model than `public`/`protected`/`private`, there's a couple of things that even I don't love about it. Having to add `shared` annotations everywhere in simple examples really does get irritating. And it's especially difficult to justify the need for `shared` when the declaration and caller are defined in the same file. Finally, since we say you can't do type inference for `shared` declarations, there are actually some cases where type inference is disallowed that would actually be perfectly acceptable from the compiler's point of view.\r\n\r\nSo here's an alternative visibility model, that builds on some discussions we've had previously. I'm not so much arguing for this model, as putting it out there to see if you guys bite.\r\n\r\nThe rules would be:\r\n\r\n1. Any declaration is visible to all other code in the same compilation unit (file).\r\n2. A declaration annotated `shared` is visible to all other code in the same module.\r\n3. A declaration annotated `shared` contained in a shared package is visible to other modules.\r\n\r\nAmong the interesting consequences of this design:\r\n\r\n* In simple examples, where all code can go into one compilation unit, there is no need for any `shared` annotation at all. Furthermore, very few explicit type annotations would be required.\r\n* There is no support for package-private visibility (but we've really struggled to find practical use cases for this).\r\n* Moving a declaration from one file to another within the same package can break code (though we have a couple of quick fixes in the IDE that can pretty quickly take care of this).\r\n* There is a \"scope\" (of visibility) that is not a namespace, nor even part of the block structure of the language. A compilation unit is not a namespace.\r\n* I would have to rethink the whole brain-hurty issue of the relationship between visibility and refinement. I'm pretty sure I managed to prove to myself that the current model doesn't have any pathological cases (where refining a member would reduce its visibility), but I think that only worked out because every visibility scope is also a block in the block structure of the language.\r\n\r\nI find the last two points a bit difficult to swallow. If we required that all code in a package were defined in the same file - which I definitely don't think would be an acceptable requirement - I would find this whole model *much* more natural.\r\n\r\nNevertheless, the truth is that I would simply *love* to be able to introduce the language with examples that don't have `shared` splattered all over them. And I also love how this model works so naturally with our type inference restrictions.\r\n\r\nSo, again, this is a request for community feedback. Note that we won't be making any changes to the current visibility model in M1, but we could consider changing the model in M2 or perhaps even in M3.\r\n","assignee":null,"id":2301320,"number":56,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[{"name":"request for feedback","color":"0b02e1","url":"https://api.github.com/repos/ceylon/ceylon-spec/labels/request+for+feedback"}],"title":"Alternate visibility model","closed_at":null,"html_url":"https://github.com/ceylon/ceylon-spec/issues/56","url":"https://api.github.com/repos/ceylon/ceylon-spec/issues/56","milestone":null},"action":"created","comment":{"created_at":"2011-11-21T16:49:13Z","updated_at":"2011-11-21T16:49:13Z","user":{"gravatar_id":"6c8086dafa5d75376d34445c011e789f","id":1206375,"url":"https://api.github.com/users/ikasiuk","login":"ikasiuk","avatar_url":"https://secure.gravatar.com/avatar/6c8086dafa5d75376d34445c011e789f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"body":"\r\n\r\nSorry, but I don't really like any of these suggestions. Mixing the concepts of scopes and source modules just seems like a bad idea. And the modified semantics of \"shared\" are just slightly too complicated.\r\n\r\nWhat about restricted sharing:\r\n\r\n    // visible everywhere in myPackage, but not outside\r\n    shared(myPackage) String hello = \"Hello\";","id":2817551,"url":"https://api.github.com/repos/ceylon/ceylon-spec/issues/comments/2817551"}}