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