About Monkey 2 › Forums › Monkey 2 Development › Inline member visibility
This topic contains 4 replies, has 3 voices, and was last updated by
cocon 2 years, 3 months ago.
-
AuthorPosts
-
December 18, 2016 at 6:42 pm #5877
Wouldn’t this be nice?
I think that it would be nice to set member visibility inline, since you can compact the code better, save some lines.
Monkey1234567891011121314151617181920Class TestPublic <--- Parser: "OK, now I will consider the following as public."' although by default visibility is public you get the idea.Method Public1()EndMethod Public2()EndProtected <-- Parser: "OK"Method Protected1()EndPrivate Field ID:Int ' <--- Parser: What an explicit member visibility? OK, this is private".Private Field Name:String ' <--- Parser: Same as well.Method Protected2() ' <-- Parser: Sorry pal, when you set explicit member visibility you cancel the active mode,End ' now I will fallback to default mode which is Public.EndA typical use case:
Monkey123456789101112131415161718192021Class TestPrivate Field _name:StringPublic Property Name:String()Return _nameEndPrivate Method Private1()EndPrivate Method Private2()EndPublic Method Public1()EndPublic Method Public2()EndEndFunction Main()Local t:=New Test()t.Test()EndDecember 18, 2016 at 9:37 pm #5883I *had* thought sticking private into a class body would make the following methods private but it seems to do nothing silently public private and protected are all very useful for library writers…
December 18, 2016 at 11:47 pm #5897I *had* thought sticking private into a class body would make the following methods private
It does – but stuff in a file can ALWAYS see stuff in the same file which may be tripping you up. Kind of a budget ‘friend’ mechanism, but one I like so it’s staying even if you hate it! ‘D does it too’ is my usual excuse…
As for…
Private Method MyPrivateMethod()
End…I actually quite like this, the only question being does it change the ‘default’ access to private too? IMO, it shouldn’t, but I can’t give any particularly logical reason why, so I’ve been reluctant to add it. I do want it sometimes though…
December 19, 2016 at 12:55 pm #5914… ah the penny drops, I’ll make a comment in the online docs if I can find somewhere appropriate…
December 25, 2016 at 4:21 pm #6023I actually quite like this, the only question being does it change the ‘default’ access to private too?
I did some code uses cases, but it won’t make a point posting them. For example in C++ you declare visibility regions and place the members there accordingly. In C# you get by default an X class scope for members, any other type of visibility must be declared explicitly at any time.
Monkey currently uses the concept of C++, the bottom line is that this change must come as a “line-saver” and not as a “concept-changer”.
I have created a matrix of possibilities in Spreadsheets and here is what I found. It looks like #1 is the winner:
12345Inline Scope Changes Default Scope The default behaviour with the only benefit of saving lines. The default behaviour with the additional inline benefit.Inline Scope Does Not Change Default Scope The default behaviour with the benefit of not affecting the global scope at all. This will introduce two visibility scopes, the inline one and the default one, might cause ambiguity.Inline Scope Resets Default Scope This will reset the default behaviour back to the default public. Same as 2, but with three scopes at the same time: The default, the one user set, the inline one. -
AuthorPosts
You must be logged in to reply to this topic.