On Sunday, 15 January 2023 at 03:02:57 UTC+11 [email protected] wrote:
On Sat, Jan 14, 2023 at 7:34 AM Bram Moolenaar <[email protected]> wrote: 
> 
> Currently I decided to keep it relatively simple and only provide three 
> ways: 
> 
> - public: read and write access, using the "public" keyword 
> - default: read access only, no keyword used 
> - private: name prefixed with an underscore 
> 
> Within the inheritance tree there are no limits, a child class can 
> access all members of a parent class and vice versa. There is no 
> "protected". 
> 
> Making the read-only access the default has two reasons. 
> 
> First of all, it is the most useful and recommended way to declare 
> object members. It avoids having to define "getters" while disallowing 
> anybody changing the values. 
> 
> Secondly, using "public" and "private" keywords is very common, but 
> there is no widely used keyword for read-only. 
> 
> One thing could still be changed: Instead of using the underscore prefix 
> to indicate "private" we could use the "private" keyword. Both are used 
> by popular languages. Although using "private" is more common, more 
> recently developed languages use the underscore prefix. Thus I would say 
> both are acceptable choices. 
> 
> # currently: 
> this._member 
> 
> # alternatively: 
> private this.member 
> 
> The main advantage of using the underscore prefix is that the "private" 
> property can also be seen where the member is used. The main 
> disadvantage is that it's a bit obscure for those users who haven't seen 
> this syntax used this way before. 
> 

I prefer the first approach as it is much easier to spot the private 
variables 
in the code. 

Regards, 
Yegappan 

> Opinions? 
>
 
Oh, I created https://github.com/vim/vim/issues/11827  but wanted to reply 
to this thread.

In my opinion, this could all be simplified a lot, if all variables are 
public by default, and are private if they start with an underscore.
So, there would only be two visibility scopes, not three to think about.
Also, using an underscore prefix is simple, and Yegappan brings up a good 
point, because it means you can just look at the variable name and see that 
it's private, without needing to go back to the declaration.

If you can make the default be public, and you use underscore for private, 
then you don't need any private or public keywords at all.

One final thought, if it is not too late to suggest this - maybe the horse 
has already bolted...   I started learning ruby last week, and noticed that 
they use @variable_name for member variables.     

So, instead of using the "this." prefix, vim9 could specify that member 
variable names must either use the @ prefix for public, or use the _ prefix 
for private.   ie., all member variable names must have one of these two 
prefixes.   I think this is worth considering, because it's simple, clear 
and explicit.  You no longer need the following keywords;  "this", "public" 
and "private".

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/cfda2289-53d7-4f1b-83c8-f875041552d8n%40googlegroups.com.

Raspunde prin e-mail lui