On 23/08/25 6:50 AM, Yegappan Lakshmanan wrote:
Hi all,
>From the email thread
https://groups.google.com/g/vim_dev/c/yYpFNUHdRho/m/xjgrKqMoBQAJ?pli=1
and the following items in the todo.txt file:
- Change access: public by default, private by prefixing "_".
Check for error: can't have the same name twice (ignoring "_" prefix).
This is not yet implemented. We cannot change this after releasing Vim 9.1.
Should we make this change now?
Default read-only is my preference; more precisely /not default public/.
(Hasn't changed since that thread was active.) Having worked with
vim9class, I don't feel as strongly about it as I did at the beginning
of the year; but considering how expensive function calls are, having a
read-only mechanism is not only a safety advantage.
Error if both "_foo" and "foo"; strongly think there should be an error.
The only comment I saw from Bram in the thread specifically about
default /public/ versus /read-only/ has to do with *simple* versus
*safe*. From the thread, in response to a suggestion that public should
be the default:
About public/private/read-only: Making the default public is certainly
possible. I think most languages have it that way, even though it's not
a safe choice.
I do like the read-only access. Quite often you want to disallow any
code outside of the class to change a member, so that you can make sure
the value is valid. But making it private means you have add a
"getter" and call it. [...]
Nevertheless, if we give priority to keeping it simple, making members
public by default and using the underscore for private is the way to go.
I was aghast (well, maybe just surprised) to see that
vim9script
class C
this._foo: number
this.foo: number
def Dump()
echo this._foo this.foo
enddef
endclass
C.new(3, 5).Dump()
works. I agree with this comment from the thread about allowing both
"_foo" and "foo"
No, we should not allow that, it is not only confusing, it also
makes it
difficult to change a member from private to public later.
-ernie
Thanks,
Yegappan
--
--
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/96d874d0-a3fb-eeeb-6c35-fb5b739e4c39%40raelity.com.