Hi,
I tried declaring private variable in a class using '_' as prefix, but
I can access this variable directly from outside the class. Here is
the code:-
What was the reasoning behind this decision?
Why not object level privacy?
Don't forget that we also have another kind of privacy: isolate
privacy. Everything in an isolate is completely inaccessible from all
other isolates. This is the only hard privacy guarantee we currently
have. Library based privacy is not guaranteed to withstand attack, at
least at present.
On 12 Paź, 20:14, Bob Nystrom <rnyst...@google.com> wrote:
> On Wed, Oct 12, 2011 at 11:11 AM, viki <vivekkuma...@gmail.com> wrote:
> > Hi,
>
> > I tried declaring private variable in a class using '_' as prefix, but
> > I can access this variable directly from outside the class. Here is
> > the code:-
>
> In Dart, privacy is at the library level, not the class level. You can
> access a class's private members from code outside of that class as long as
> that code is in the same library where the class is defined. (In Java terms,
> Dart has package private. In C#, internal.)
I thought Dart would be a language for large scale applications.
For me the thing I miss the most in Javascript is public/private/protected concepts and sometimes namespaces. I miss
declaring classes as classes, adding constructors and stuff like that
without all the tricks you use Javascript.
I don't know that it's as bad as you suggest where derived classes are
concerned. Where library users are concerned, however, it worries me
a little bit. While Isolates exist, it looks a little too much like
going around one's backside to get to one's elbow. Something with a
little less coding opacity might be useful.
isn't a big part of private / public / protected variables about defining their semantics and how they are to be used?A big part of the docs I've read so far on Dart is that variables don't ever have to be declared with a type but they can be to make the intent clearer and to allow for IDE warnings etc. Which I think is great, I think that making code very clear and easy to understand as to how and why it was designed that way is a good thing, so shouldn't their be private / public variables at the class level for this reason if no other? to make it clear that you can 'touch-this-safely' or to 'keep-your-filthy-hands-off' my variables.
--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
1. Class-level privacy has some advantages and disadvantages2. Library-level privacy has some advantages and disadvantages3. But when exist more than one (alternative) then this is even better.
Library-level privacy is enough for small projects with few programmers working on it.
When many programmers are working on the same library, it is, IMO, fundamental to differentiate between class-level and library-level privacy.
Darts library concept is good, including the library privacy but it's inadequate on its own.
Give us the tools we need!
I avoid "protected" inheritance where possible but it to had its place.
library can grow big overtime
>> but it has some known problems that the Smalltalk
Who here used Smalltalk? I don't use. May be you?I do not care about the problems in the the Smalltalk
Hi,
I tried declaring private variable in a class using '_' as prefix, but
I can access this variable directly from outside the class. Here is
the code:-
class A {
num _myPrivate = 5;
void show() {
print('myPrivate = $_myPrivate');
}
}
void main() {
A a = new A();
a.show();
a._myPrivate = 10;
a.show();
}
Here is the output:-
myPrivate = 5
myPrivate = 10
As you can see in main() after first show(), 'myPrivate' variable can
be changed. How to declare private variables in class.
Thanks,
Vivek
...
"There was a lot of discussion about this when we first started working on it, and that stuff deserves to be cleaned up and publicized but doing so will take awhile. "
so it sounds like object-level privacy will be implemented in just matter of time or otherwise ?
....
...for example, looking at existing javascript library, jquery, prototype ... and see how big they grow in one file... they can break down into multiple files
but it may still be under one library, and they really grow over time.
Developers may value convenience at expense of maintenance in the real world from what I observe :} although it may not be a good practice.
The amount of attention that is paid to interfaces to the library, ensuring the library is well tested through that interface, and good management of the relationship between the libraries, is what makes or breaks the body of code.
If I write a library - then in production mode it's likely that that I want to check the incoming values.
What was the reasoning behind this decision? Why not object level
privacy?
On Oct 12, 2:14 pm, Bob Nystrom <rnyst...@google.com> wrote:
> On Wed, Oct 12, 2011 at 11:11 AM, viki <vivekkuma...@gmail.com> wrote:
> > Hi,
>
> > I tried declaring private variable in a class using '_' as prefix, but
> > I can access this variable directly from outside the class. Here is
> > the code:-
>
> In Dart, privacy is at the library level, not the class level. You can
> access a class's private members from code outside of that class as long as
> that code is in the same library where the class is defined. (In Java terms,
> Dart has package private. In C#, internal.)
>
> - bob