On Monday, 26 December 2022 at 09:08:22 UTC+11 [email protected] wrote:

> On 22/12/25 1:07 PM, Bram Moolenaar wrote:
>
> With 9.0.1094, in the script that follows, attempting to read a
> classMember through  an instance fails;
>
>     echomsg c.classMember
>
> should it?
>
> No, an object does not provide a class member.
>
>
> I suppose requiring the class name makes it most clear, but I recall
> mention that classnames can get long. I suppose a getter could be added.
>
> How can you access the getter without referring to the class?
>
>
> Assuming c is an object
>
> c.GetClassMember()
>
> where the method GetClassMember() returns the classMember that was 
> declared static. 
>
> Can a class method (or should it be called class function?) be static?
>
> Nothing *is* static, the "static" keyword is used to change the meaning
> of items.
>
> I should have said "can a method/function defined in a class be declared 
> static?"
>
> I don't think it's a good idea to access static class function from an 
object instance of that class.   Also, I would not name that function with 
"Member" if it is a static function, because member implies that it is a 
member method of an object instance.  I think that could lead to confusion 
for someone else trying to read your code.
 
The difference between a function and a method is important - with regard 
to this topic of classes vs objects of the class.   According to Bram's 
preliminary doco.  Yes, class "method" can be declared static.  But then, I 
think that makes it a static class "function", and not a class "method".  

Bram, I think that the doco here is referring to a class "function", not a 
class "method".  It might be worth distinguishing between method and 
function in the doco?

Ref:
https://github.com/vim/vim/blob/b3d614369fceb891819badc941f80f08f57831f9/runtime/doc/vim9class.txt#L261-L275


One way to look at it: is it the case that any method can be invoked as
>
> MyClass.SomeMethod()
>
> and as long as "SomeMethod()" doesn't reference a variable like 
> "this.someVar" then it's OK?
> -ernie
>

How would Vim know when that is an error or not, if you didn't specify the 
static keyword when declaring the static class function.   You want Vim to 
treat it as if it was a static class function, but wouldn't Vim need to 
analyse deeper to see if it uses any object members, to be able to allow 
that?



-- 
-- 
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/656faf72-e6a1-452c-bd25-59c22a071115n%40googlegroups.com.

Raspunde prin e-mail lui