-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add public and private access modifiers to language #33383
Comments
Retitled to highlight the request. |
What's the problem this change would solve? |
It's a good question, I think it's necessary, this proposal comes mainly for two reasons. The first one is about the adoption and use of this technology, this I will explain in the following list:
The second reason, seeing it from a more technical point of view, is to make a language more secure, standard, nice to the programmer, with business vision and general purpose, this will be explained better in the following list:
Well I hope to convince and have been able to justify the proposal very well I hope this is a reality, what I have left is to give a greeting from here |
Sounds like personal preference. |
It's not the first time this has been requested, but we have no current plan to add such keywords. There is a reason Dart does not use class based privacy. The library based privacy that Dart has is allows us to syntactically detect private member accesses, and use renaming per library to allow a more efficient implementation of dynamic access. If we ever add some other sort of privacy, it's more likely to be instance based than class based. That means that you can only access such members through |
What a shame that this request is not taken into account, this was a necessary requirement to take the decision to create an ERP on this platform, I speak to you as an investor and it is unfortunate that it ends well, I will have to look at the copetence like Java or TypeScript |
My sincere apologies for commenting on a closed issue from 2018. I would like to see that too. It would make Dart almost perfect language. In my opinion, at least the It sacrifices verbosity in favor of fewer letters to type, when in fact, most of the time on development is not spent on pressing keys on the keyboard but thinking about what to type. The difference between typing 1 character, to ~15 is not relevant to the project development time, even if you multiply it to 50000. I did read and understood the concerns raised by @lrhn, but I find very useful to have the instance visibility concept available. I think the concern raised was mostly about how to detect visibility when you have inheritance. That would not be a problem if the language didn't allow inheritance (not even mixin, but compile time paste with traits) but only composition and interfaces. If I was maintaining Dart, I would still consider adding |
I think it's important to note that this is actually not about syntax. You could choose lots of different syntactic forms for the same thing, but it's the underlying structure that matters. When privacy is indicated in the name of a class member (for instance, using When privacy is indicated by a keyword in the declaration (say, It would also cause ambiguities, because you can have, say, two superclasses of the dynamic type of the receiver, each of which adds a private It would be detrimental to modular development to say that it's an error for two classes with a subclass relationship to add a private method with the same name (because then you'd have to know about all private methods in your class hierarchy, including the ones that are written and maintained by someone else). So you could claim that it's all about having a well-defined semantics for dynamic method invocations (and perhaps you would add "and I don't care about having If you create a complex library L, and anybody who wants to do so can go in and fiddle with the values of your private variables and call your private methods etc, then I think it might be harder for you to maintain L, and to interpret bug reports and so on. OK, you have a private variable called |
No idea why scope wouldn't be included and explicit. Flutter & Dart have some great things going on, but the things that are... odd?... are REALLY odd. And some of its verbosity for simple things is a little silly, while CHOOSING to leave out explicit scoping just seems like a poor choice. Same with inner classes. * shrug * |
PHP is a very common scripting language used in the industry, in my opinion it is a worthy example to follow for the syntax of public and private the way of doing things in php is very intuitive and is very similar to java or c# with less verbosity of course, PHP continues to triumph in web development where the issue of verbosity and framework is attacked much like laravel hasen that php is very nice |
If the underlying structure is what matters, let's choose a way to express the concept that is more familiar to everyone and looks less like an identifier naming standard.
I don't buy this argument. If it is private you are not supposed to call or know it exists from an external perspective.
You don't have to know all private methods in your class hierarchy. That is not an issue in any OOP language and I don't see why it would be in Dart.
I think what you are understanding by private is what I understand by protected. Are you assuming private members would be accessible by inheriting classes? This makes a lot of difference in the discussion because if private is only available within the class, it should never be accessible even if done dynamically. I think as @Ing-Brayan-Martinez mentioned, you should take a look at how it works on PHP (and private works the same way in Java, Kotlin). I quote from PHP manual:
I think Dart does not need to support (as described above) such protected behavior Maybe we can avoid inheritance at all in favor of composition? |
@fabiocarneiro wrote:
I understand that this kind of familiarity can be seen as attractive (especially for developers who are working in a highly heterogeneous environment), but at this point it would be a massively breaking change to switch from the
Dart private methods support overriding because the scope of privacy is the library (so you can have a class hierarchy with normal method overriding applied to private methods). In that sense, Dart privacy is "module privacy", somewhat similar to the Java notion of being package private. This means that you cannot just choose to jump directly to the statically known implementation of a given private method, and this means that there must be some mechanism that enforces the distinction between the private When the In PHP, the privacy scope is the class, and it's sufficient to compile private methods such that they check that the call site is in the same class (and for So my point was that we cannot accept this kind of ambiguity, but with a
Protected is usually associated with the subclass hierarchy and unrelated to the module structure (in Dart: library structure), but you are right that privacy in Dart does include overriding relationships, which is not the case for class-based privacy. So the source of confusion may be that what I understand by private (in this context) assumes a relationship with privacy in Dart.
If this is a proposal for dropping the current notion of privacy in Dart (library scoped privacy) and replacing it by a class scoped notion of privacy then we're looking at an even more massively breaking change. On the other hand, it would be possible to add a completely new notion of class scoped privacy for members, and it could use a class C {
C next;
private int foo() => next != null ? next.foo() : 42;
}
var x1 = new C().foo(); // Compile-time error.
var x2 = (new C() as dynamic).foo(); // Dynamic error. This notion of privacy would compete with another one where invocations of private methods are restricted to have the receiver Finally, it might seem more natural for Dart to build on top of the existing privacy mechanism (and enforce that |
Thanks for the patience, and I need to say that I love this discussion. In the Dart context, Private means something else, but for me and others, when we request this feature, we always mean "object scoped privacy" Java package-private is also probably not the best name for this concept of visibility within a library. The absence of the modifier is what declares Package-private in java, and if you compare to the other modifiers, it behaves much more similarly to Protected than to Private. Protected is the same, but also allow visibility from other packages. That said, If I were giving it a name on the Java context, I would call it package-protected instead of package-private. The same reasoning can be applied to Dart, as the
That said, what all of us are requesting here is the introduction of a Then the question is: Can this private modifier be implemented without performance impact? The way I see, it is a very straightforward process to detect in compile-time the call to Private members from external places. In the Dynamic contexts, I can see there might be a check to see if the member is visible or not, but isn't that the same check as seeing if it exists or not? Isn't the difference that now the list of existing methods would be a list of visible methods? For me, the source of your concerns would be the introduction of a "protected" keyword, and that is NOT what we are asking. One important factor here is also not only the performance but how likely people are to adopt the language. It is true that Dart is a huge success, but I also can see a lot of people complaining about its design choices. In the end, if people are not willing to adopt the language, its performance does not matter. In the end, we can all be writing code in assembly to achieve such great performance. |
Thanks! Tomorrow is a holiday here, so I'll just add a short remark and then go home ;-) A The tricky part is that this would make it hard to deal with |
If you love clean-code like me, then you hate the For me it would be enough if In other words, Or at least we could have a |
Dart is going to add more type safety, and we don’t want to add access modifiers cause of dynamics?.. Guys, we are migrating to flutter from awesome Kotlin and Swift, not from stupid js. Dynamics is bullshit, nobody never use it in big production apps. Stop being js and just add modifiers, instead of ugly _ and @Protected |
Access modifiers, please.You want more people to join Dart and Flutter? Show that you care about them. Access modifiers are an important part of Object Oriented Programming, and just saying "we prefer this way" just denote you are not about end users, but only about the closed community developers working on Dart/Flutter who take the naming decisions. I have more poor naming decisions to point out, among them, Padding(padding), Opacity(opacity), instead of Padding(value), Opacity(value). Saying "the padding of the Padding" and "the opacity of the Opacity" is redundant, and we are supposed to be against redundancy. I've read all the reasons for not using access modifiers and going the "everything is public, unless you use underscore" route. There are all non-sense. Then, there are decorators (meta tags) to tell that something is protected... so, why going the meta tags route, instead, of, erm.... using private, public, protected keywords, like the rest of the OOP languages??? It's like saying "Hey, everyone, notice me! I'm different! Everyone else is going right, but I'm going left because...reasons! Durr durr!" Like the comment above me: Stop being js and just add modifiers, instead of ugly _ and @Protected. |
We need a way to modify accessibility of classes because in favor of For me, the most obvious thing to have as functionality is having a way to modify accessibility scope of some classes into a specific folder. This is very common case IMHO, e.g. you have a Screen widget, there are state class(es) file(s) related to it, there are widgets related to it and goes on... I don't want to import anything from there to other Screen classes. I think this is very common concept every Flutter developer faces during development. Golang has best design choices for this topic, you can borrow some concepts from it. Uppercase => public, not slowing down the typing. Don't wanna import anything from anywhere => create another package. I may open a proposal for this. |
@eernstg |
I think class privacy would have the same issues as library privacy. Instance privacy could presumably be enforced for dynamic invocations (say, when generating native code) by (1) checking whether the callee is instance private and, if so, (2) throwing unless the receiver in the previous activation record is the same as the receiver in the new activation record. However, that may not be cheap (for instance, the receiver may be stored in a register and may have spilled into any location of the previous activation record). It would probably be more useful to decide up front that some kinds of access control will guarantee enforcement, so they can be used for optimizations and other "hard" purposes. Others are just used to emit diagnostic messages when it's known that there is a violation, and we accept that there can be a number of violations that won't be detected. The latter kind is useful as an aid in the approximate enforcement of certain software engineering properties. |
Absolutely wild that this is considered "closed not planned" considering its ramifications for development. If I want to create a private method that should not be used by other classes in the package I have no options in Dart except for communicating its private nature to team members. If nothing else, this also clutters code completions. While no code is truly self-documenting, this absence means that Dart code cannot approach self-documenting. |
There’s always early 90s Visual Basic notation of “p__” on private variables.
FWIW I’ve decommissioned one flutter project this year. I think management is considering another for next year.
… On Oct 24, 2020, at 4:13 PM, lmcdougald ***@***.***> wrote:
Absolutely wild that this is considered "closed not planned" considering its ramifications for development. If I want to create a private method that should not be used by other classes in the package I have no options in Dart except for communicating its private nature to team members. If nothing else, this also clutters code completions.
While no code is truly self-documenting, this absence means that Dart code cannot approach self-documenting.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
also t would be great to have package access modifier... not everyone likes to work with files 50k lines each just to reduce visibility... |
Dart should has the access modifier. a thing is uncomfortable is when I have a class, the variable is private "String _abc" and it is being called many places in the class, then i want to public that variable, i change it to String abc. i have to change that name in entier class. If we have the public and private keywork, we just change only one place. Please add access modifier. And the same request for method. |
You guys are making this a longer discussion than it needs to be. Implement a keyword Basically, what most people were looking for was to be able to write this:
instead of:
No need for a You might argue that you would have to clarify in the docs that the This discussion reminds me of JavaScript's private class fields proposal, equally long and unnecessary, and they still chose the worst option. Anyway, just my 0.02$... |
@CostachescuCristinel there are a lot of comments to add |
I didn’t say it wasn’t a worthy pursuit; the underscore is flat out stupid in terms of productive flow of typing - before getting into the idiocy of it being unlike any other language.
I’m just saying if you’re going to pick one thing as your ‘must have’, there are way bigger fish to fry than the idiotic underscore.
$.02
… On Apr 13, 2021, at 11:42 AM, Rostyslav Lesovyi ***@***.***> wrote:
@CostachescuCristinel <https://github.com/CostachescuCristinel> there are a lot of comments to add package, protected etc.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#33383 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/ABZHS6NDSBWSBYLBU6O3MDLTIRRADANCNFSM4FD23YCQ>.
|
@MatrixDev I would agree with them on looking after such language features, for good OOP reasons I'd add. But this could be a topic for another discussion. As far as I can see, the initial requests were only about getting rid of that underscore notation in favor of an explicit Anyway, I'm not going to make this discussion any longer. I ended up here from the Dart language tour, and I was just amazed by the lengthy discussion. My best regards and good luck to you all :) |
From what I can see, there are two major points in favour of the
But having a look at the "greater structure", I feel there are higher priority points that favour a What are the benefits of having dynamic calls in productive code or for productive coding? In a similar manner, what are the benefits of allowing overriding private members? Most languages don’t allow this (or mark them using the Again, looking at the greater structure, having a property of a field encoded in the name is a bit obscure. From Dart’s overview page:
This also seems a bit contradictory. What is Dart, statically typed or dynamically typed? Can you reasonably have both? If Dart prefers to be dynamically typed, and values highly-efficient private member overriding over de-facto standards from other languages, so be it. |
@scbabacus-midnight you can't compare Kotlin multi-platform with Dart. Dart is mostly used in combination with Flutter. Kotlin at this moment doesn't have even a fraction of platform-specific functionality nor libraries as Flutter does. As I suggested previously Dart can have both - static and dynamic typing (adding private/protected/public without removing
PS: this argument can go the other way as well - you're not the only one, a lot of people would love to have proper static typing. |
@MatrixDev Thank you for Original post:
|
In Android Studio and IntelliJ, just place the cursor over the variable name, where it is declared and type SHIFT + F6. You can also use this tool to rename methods and classes too. It will rename in the whole project. |
And you'll have huge diff in the commit if variable is used in multiple files. Also this might lead to merge conflicts. |
Yeah. I know that, but i meant we would change a lot of line. And when we commit the file. It's so hard for review the code changed. |
I agree. The PRIVATE keyword would be better. |
Why is this issue still open? This isn't the right place for debates and
subjective opinions. This issue can't be "solved".
…On Wed, Dec 8, 2021 at 1:10 PM cedvdb ***@***.***> wrote:
Interesting that nobody has been able to give any concrete example as to
what problem class privacy would solve
Let's flip it around, I've not seen many use cases where _member is
accessed from another class in the same file.
Like this:
class Test {
final int _priv = 3;
}
class Also {
Also() {
print(Test()._priv);
}
}
There are some use cases for public APIs, other languages have it too,
like Java default access modifiers, where values can be accessed only
within the same folder. The issue is that to have this feature, you have to
put the classes in the same file, which is *really* intrusive. I find
codebases where class are not separated into files harder to navigate, to
each his own I guess.
Also features like this
<dart-lang/language#2005> have some
inconsistencies built into it because of the _.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#33383 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASS4QSH7BR4R7BMUYYNSM3TUP44JVANCNFSM4FD23YCQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@CharlyZA-2, is it still open? Also this is the only place people can realistically debate and give their subjective opinions. |
There are objectives arguments to be made why access modifiers that give finer control, like "package private" (java) can make for better public api of "package". It is quite frustrating that the only way to have that is to put everything in the same file. However I hope there is going to be some sort of |
@cedvdb use "part" and "part of" |
If encapsulation keywords would be too much of a pain to implement, why not add more encapsulation symbols for variable names for the language? Already, we have nothing=public, Sure, it's confusing as hell, but Dart's use of underscore for file-protected is already unintuitive. |
I wouldn't say it's unintuitive as it's been a convention in various languages. Maybe those symbols would be a problem on some keyboards too. What I'd like is to make everything "internal" when there is no "public" access modifier in front and add a private keyword with the obligation to use "_". The internal change can be handled by dart fix. That plus some sort of module that doesn't require a full fledged package, it's too slow and bloated currently. EG:
|
I can hardly imagine what Flutter development would be like today if Google had opted for Python instead of pushing their own programming language. Python is by far the most popular language right now: https://www.youtube.com/watch?v=qQXXI5QFUfw |
Dart has easy to write syntax, one of the reasons for that is the use of _ as access modifier. |
I am just learning Dart right now and reading through official docs, I have got here. I see many developers (especially Java and such lang related ones) complain about not having Think about AI today and what it is developed in? Why? Why do people want to use Python? Maybe because even though they write more expensive in work dynamic code, they achieve the same goals or outstanding goals (like implementing AI) using less concepts? Think about who Dart language should be attractive to today - Java devs, C# devs or Python devs? Stop crying about having to use python-like |
If everything was so nice flutter team wouldn't introduce ugly workaround in the form of |
I see that no one liked my comment above. I understand and accept this. In fact, Flutter's biggest problem isn't the language. Dart is an excellent language and I'm surprised it isn't adopted as much as others. The biggest problem I've found with the Flutter framework is the constant breaking of backwards compatibility and the hell of dependencies between libraries that this entails. With each new version it is necessary to rewrite a lot of code and test everything again. What is the advantage of having a single code base if it is always changing? I've been away from Flutter development for some time because of this. I hope this has improved and that new versions mature the standards, as it is a fantastic framework. |
Dart team need to concentrate more on the current problems facing by JAVA / C# /TYPESCRIPT coders. |
Hello everyone, I've been analyzing the answers they gave me in issue #33104 33104, and I'll summarize them in a single proposal, which I consider a necessity and the most important, since the translation is not exact, I'll explain it with a couple of examples:
The proposal is: Add the reserved word public and private only.
An example with flutter.
The text was updated successfully, but these errors were encountered: