On 23/01/24 10:23 AM, Ernie Rael wrote:
On 23/01/23 4:53 AM, Bram Moolenaar wrote:
I expected a lively discussion about alternatives for the class
implementation, but nothing much happened. Does this mean that most
people agree with making this changed:
1. Make object members public by default. They can be read and written
from anywhere.
2. The only other possibility is making the object members private.
This is done with the existing mechnism to prefix an underscore to
the name.
This simplifies things, there is no "read-only" access mode, which is
currently the default. There is no need for a "plublic" keyword. This
is a bit limited, but it's simple. And making things simple is part of
the goals for the Vim9 script syntax.
Unless there are relevant objections, I'll make this change.
In a previous comment on this, I said
Guess I'm looking for a way that a trusted group of
classes can have full access; but I'm not sure how important that really
is (and I'm not sure how I feel about a bunch of classes in a single
file).
But while exploring porting some python code to vim9 I realized that I
generally use lots of classes in a single file; but they are nested
classes and that's one of the primary ways that private members are
used from the outside (I'm talking about java, not python).
I can probably achieve a lot of this by having a given object save
functions/lambdas that access private stuff into function variables
within the file and then use those functions from within the file.
Sounds messy, but I don't like having stuff public outside of trusted
code.
I'm trying to experiment with this approach, but classes aren't ready
for it yet. Here's what I'm thinking might work. It depends on a static
class method being able to access private object members, something like
the **private** method `StaticModX` in the following, and then the func
`AccessXxxx` give stuff in the file access to private members. (Might
want to have InitLocalAccessFunctions private and executed only the
first time the constructor is called)
var AccessXxxx: func
class X
this._xxx: string
def new(this._xxx)
enddef
static def StaticModX(x: X, val: string)
x._xxx = val
enddef
static def InitLocalAccessFunctions()
AccessXxxx = X.StaticModX
enddef
endclass
X.InitLocalAccessFunctions()
o = X.new("some_string")
AccessXxxx(o, "different_string")
-ernie
--
--
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/566b572b-dde4-ad60-5f0b-3478ae66134d%40raelity.com.