in the spec is is said that there will be abstract classes one day in Dart.
Now I know we have private and public vars with _ or not _.
I think it will be very useful to have some kind of "protected"
variables and "protected" methods in Dart. They should imho only be
accessible from the extending class (and their descendants).
Not sure if this is already discussed or not or what your feelings are
about protected stuff.
Cheers
Christian
Hello,
in the spec is is said that there will be abstract classes one day in Dart.
Now I know we have private and public vars with _ or not _.
I think it will be very useful to have some kind of "protected"
variables and "protected" methods in Dart. They should imho only be
accessible from the extending class (and their descendants).
Not sure if this is already discussed or not or what your feelings are
about protected stuff.
Excellent!!!!!
>> Now I know we have private and public vars with _ or not _.
>
> Yup. Keep in mind that this is library private, not class private. So it
> isn't like "private" in Java and C#. It's like "internal" or package
> private.
Oh- thanks for mentioning it, I actually missed that fact. But
honestly I am not very glad to hear about this. One needs to rely that
people cut out their libraries very carefully and well designed. But I
can imagine that some folks just put everything into one library just
to get done quickly. After all they have all the problems one has when
using public vars only. And they will blame Dart for it, because they
didn't understand and tweet: "privacy mechanism doesn't work"
Actually I would prefer to have private members on a class privacy
scope. Some people are even using the underscore syntax to identify
private members in code. Their expectation is of course that they are
private on class level.
That being said, I like the _ idea. It might be ok to have more suche
identifiers, similar to uml maybe.
Like:
bool _stuff; // class scope
bool *stuff; // package scope
bool +stuff; // protected scope
>> I think it will be very useful to have some kind of "protected"
>> variables and "protected" methods in Dart. They should imho only be
>> accessible from the extending class (and their descendants).
...
> But it also adds complexity to the language. I think for now the current
> plan is to try to live without it and see how it goes. Most dynamic
> languages don't seem to have it and still get by OK. I think we can get most
> of what we want just through documentation and convention: just make it
> clear to users which methods should be called only by subclasses and which
> can be called by anyone.
Yes, most dynamic languages don't have it. And I hate it. For example
PHP: they don't use protected, just private and public. Sometimes I
need to put some stuff to public, even when this is weird, just to
avoid to copy paste the same code all over again.
The conventions and documentation you mentioned might work if you have
a few hundred lines of browser side code. But you might think
different when you start to write server side code for the app engine.
At least I would love to see Dart executed on the server side and
replace Java in some cases.
Complexity in language: my argument is, not using class level privacy
might make this language more complex as necessary because in my
opinion this is what people expect.
Of course, I am not really a language designer, this is just my taste.
Thanks for your explains Bob, they are very helpful as always.
Cheers,
I'm a Java/Flex developper and to me the privacy system in Dart is
just a (bad) joke. I cannot see it otherwise than a huge regression
compared to "traditionnals object oriented languages" such as Java /
C# / ActionScript / D...
I agree here
> Libraries should generally be reasonably-sized and have well-defined
> interfaces. I would agree that naming convention for privacy and
> public-by-default isn't exactly the best way to define interfaces, but that
> would be the statically typed me. The culture of "expose everything by
> default" is pretty common in dynamic languages, if I can tell, and Dart is
> dynamic in its heart.
I agree there should be "good sized" libraries. But i am afraid not
every developer out there has the competence to do so.
> Just to let you know that there are other opinions as well.
Cool thank you.
Actually I have started to think about the benefits of such a behavior again.
Cheers
Christian
>
> LT
Oh- thanks for mentioning it, I actually missed that fact. But
honestly I am not very glad to hear about this. One needs to rely that
people cut out their libraries very carefully and well designed. But I
can imagine that some folks just put everything into one library just
to get done quickly. After all they have all the problems one has when
using public vars only. And they will blame Dart for it, because they
didn't understand and tweet: "privacy mechanism doesn't work"
Yes, most dynamic languages don't have it. And I hate it. For example
PHP: they don't use protected, just private and public. Sometimes I
need to put some stuff to public, even when this is weird, just to
avoid to copy paste the same code all over again.
The conventions and documentation you mentioned might work if you have
a few hundred lines of browser side code.
At least I would love to see Dart executed on the server side and
replace Java in some cases.
I agree there should be "good sized" libraries. But i am afraid not
every developer out there has the competence to do so.
On Wed, Nov 30, 2011 at 2:12 AM, Christian Grobmeier <grob...@gmail.com> wrote:
Oh- thanks for mentioning it, I actually missed that fact. But
honestly I am not very glad to hear about this. One needs to rely that
people cut out their libraries very carefully and well designed. But I
can imagine that some folks just put everything into one library just
to get done quickly. After all they have all the problems one has when
using public vars only. And they will blame Dart for it, because they
didn't understand and tweet: "privacy mechanism doesn't work"That's a concern of mine too. The fact that we don't use a familiar "private" keyword helps a little, I think. Beyond that, the best we can do is what we're doing now: communicate it clearly and frequently.If Dart is to have any concept of privacy, I do think that library private is more useful than class private. Privacy in Dart (and other languages) isn't for security, it's for maintainability. You mark things private to ensure that people don't need to know about them in order to use your code.From that angle, library private makes sense to me. I consider a library to be a unit of maintenance. If you're modifying a library I think it's reasonable to expect you to understand most of its code. You should be able to load the whole library into your head, so you don't really need to make parts of it private and hidden from other parts. If you do find yourself wanting that, I think that's a sign you should break your code up into smaller libraries.
Yes, most dynamic languages don't have it. And I hate it. For example
PHP: they don't use protected, just private and public. Sometimes I
need to put some stuff to public, even when this is weird, just to
avoid to copy paste the same code all over again.I feel weird about it too sometimes, but I think that may just be my C++/C#/Java background. People who live and breathe in dynamic languages seem to be OK with it.
The conventions and documentation you mentioned might work if you have
a few hundred lines of browser side code.We've written a good bit more Dart code than that and so far privacy hasn't been a real problem. Swarm is a few thousand lines of code broken into a bunch of different libraries.
Thanks for sharing your thoughts.
well in theory this is nice. You somehow "force" people to make nice
lIbraries. But there are many I know who failed already with
"separation of concerns" in Java. It will not be easier for them now,
as they need to think about libraries which I consider a core aspect
now.
>> The conventions and documentation you mentioned might work if you have
>> a few hundred lines of browser side code.
>
> We've written a good bit more Dart code than that and so far privacy hasn't
> been a real problem. Swarm is a few thousand lines of code broken into a
> bunch of different libraries.
OK I need to trust you on that atm.
It might make sense not to refer to "private members" etc to private
stuff. Guess it should be a new term, clearly showing this is not the
privacy which is known in many languages (even javascript, somehow).
For example: library scoped.
Cheers
:-)
I wish this will happen - but honestly, I have seen a great designed
system of two guys totally killed by six developers who started to the
daily business with it. i doubt that the big mainstream is really
caring on "how to do right". I think many people just want to get it
done and then move to home, grab a beer.
Anyway i will keep an eye on the developments. If you are right on
that, and people start to behave and write good encapsulated libraries
in the Dart Way, then I promise to buy you a beer on the next
conference we meet (assuming you drink beer).
Cheers
Christian
>
> - bob
We do use protected in PHP. \o/ Certainly in PHP 5.
Protected variables or methods can be accessed within the class
itself as well as subclasses and superclasses.
Regarding privacy in Dart, having library privacy only doesn't seem
a big deal to me. It does at least provide a way of blocking off internal
details from external use; and I think we should be able to trust
developers of a library to police their own use of "private" items within
that library itself.
And if someone mis-uses something within a library or application
and breaks something, well... that's what the unit tests are for. ;)
You are absolutely right. It will be a good reason to reject Dart and it's heart breaking.
You are absolutely right. It will be a good reason to reject Dart and it's heart breaking.If someone wants to reject Dart based on its novel approach to privacy, I have no problem with that. But I think that class-based privacy only complicates stuff in large-scale application development
and that designing classes to be both subclassed and used from the outside is almost always a bad idea.
LTP.S.: this thread is almost a year old -- what about starting a new one?