Replies: 5 comments
-
I don't remember which issue/PR/discussion this came up in before and there's not really any reason to find it (I'm content to believe that I could find it if I tried). I did rather enjoy the "it's a feature"/"that's what they all say" exchange. So you're saying
It is true that private static members can not be accessed by derived classes. Is something I'd like to do prevented by this access model? Of course not, programmers can do anything. But how much extra work is needed to do something the more common model can easily do? Worst case, I can do something like, in a single file
Not pretty. The question of whether or not I'd need to do that is hard to say. I wonder what it would take, if the current model is released in vim9.1, to add the ability to "export a class with features inaccessible to derived classes". How about
does that work such that class (not object) privacy is available and old code continues to work? |
Beta Was this translation helpful? Give feedback.
-
I don't remember which issue/PR/discussion this came up in before and there's not really any reason to find it (I'm content to believe that I could find it if I tried).
#12932
// if you're willing or still cost OK to change, please perhaps just think that 'default' one
// note that term 'public' there actually should be meant 'protect' which i said at #11827
// public still was public
…--
shane.xb.qian
|
Beta Was this translation helpful? Give feedback.
-
I'm not quite sure what you're getting at but it was #13195, which is related but they can be discussed separately. Fixing this issue in isolation would actually make that issue worse. Access controls seem a bit of mess to me but I think the export and class boundaries are the only two of real interest if we're simplifying as much as possible. I've found the Zimbu spec very illuminating. In my opinion, a lot of the rough edges in Vim9 script are the result of using a subset of its features that don't work all that well in isolation.
Essentially, but I'm derailing this with half-baked conceptual musings as usual. :) The bottom line is that "private" as I'd argue it's generally understood isn't the same as available here. There's pragmatic and theoretical reasons that "protected" is often discouraged but I think standard practice is good enough guidance. I can think of few modern languages that have done away with "protected" access but Dart, for example, later added some support for this with an annotation for the analyser.
I don't think that matters.
I might be misunderstanding you but are you saying you've never used "private" with intent in Java? You escaped indoctrination into the OOP cult and its love of private data? :)
I find it hard to believe anyone would design a language with this mix of keywords and sigils. :) Making I think just making If no one "has anything to hide" (always a red flag) then the help should at least be reworded so that there's less confusion. |
Beta Was this translation helpful? Give feedback.
-
i think it was #12932 which i said above comment, a loooong "discussion".
😄 even you'd like to change, it had been too late, |
Beta Was this translation helpful? Give feedback.
-
[snip references about script access into classes and Zimbu]
[I edited the original post to add (3)]
Yeah, what does the
I'm not saying that at all, my default is private. IMHO, distrust and paranoia well serve the programmer. But it's possible that in a controlled programmer environment...
Yes. But I seem willing to accept extraordinary measures to move forward from where we are.
I'm confused by that statement. I meant that in the current language
With no protected? I wouldn't like that.
Totally agree with that. I like protected, in spite of it's theoretical issues, and inheritance. I also like composition. Each is useful and can be overused. The screwy One reason to defer class private is that perhaps the access model could be extend with #13195 at the same time. |
Beta Was this translation helpful? Give feedback.
-
The underscore prefix is used to declare what are referred to in the help as "private" features of a class. In the case of instance variables and methods these actually have what is commonly referred to as "protected" access, i.e., subclasses also have access.
This is unusual and I'd expect that most programmers with a background in any mainstream languages from the last thirty years would reasonably expect these to be class private. While a case could be made for an object-based rather than class-based view of encapsulation, and one I probably favour, it's far from the norm.
Being unable to export a class with features inaccessible to derived classes seems like an awkward limitation given standard OO modelling practices (for better or worse).
The help is also not very clear on this topic.
Beta Was this translation helpful? Give feedback.
All reactions