What do you think about their rationale? It made sense to me.
"Privacy is indicated by the name of a declaration -- hence privacy and
naming are not orthogonal. This has the advantage that both humans
and machines can recognize access to private declarations at the point
of use without knowledge of the context from which the declaration is
declared."
--
Seo Sanghyeon
Cheers,
-Maurice
On 11-11-12 9:10 AM, Jan wrote:
> I'd rather want to have a 'public' modifier. All variables are private
> unless explicitly exported with the 'public' keyword. I also think
> that using an underscore is a bad idea because it is difficult to
> change afterwards.
>
> And the same for the 'final' keyword: all variables are final unless
> explicitly declared with the 'var' keyword, like so:
>
> String name = 'Bob';
> var int age = 26;
>
> name = 'Bill'; // error
> age = age + 1; // Ok
>
On Oct 10, 3:13 pm, Larry Cable <larry.ca...@gmail.com> wrote:
I also don't agree with Zexx, although I do not have a proper metric.
Motivated by my Scala exploration I made exactly the same experience. When reviewing older Java code I found that very often a final keyword could be added without harm. On some few places the structure had to be changed a bit to apply a "final only" approach. There were very few places where explicitly a non-final var was of advantage or even necessary.
So if that works in Java, it is only a matter of style and perhaps a bit support by the language (e.g. convenient loop constructs)
I strongly am of the opinion that Scala and F# will get more attention in the future, and thus the object functional approach. Every language coming up now should try to not only appeal current average developers but support the style of the next-generation average developer. And "use final" will be on top of the best practices hints to be found in every learn-to-program tutorial.
Thanks.
My main accent that explicit access modifiers used many languages by
many years.
public / private / protected / internal / etc...
Why re-invent same but using magic prefix?
On 13 ноя, 18:20, Iph <seanmyers0...@gmail.com> wrote:
> On Nov 13, 11:00 am, fddima <fdd...@gmail.com> wrote:
>
> > Lang, must have accessibility features, or doesn't have. DartSpec
> > defines not only underscore as private, but and 'm' prefix as library
> > visible.
> > What it is mean? 'my' << it is library scope??? It is completely
> > nonsense.
> > Use classic explicit modifiers, and let developer's choose which
> > naming conventions it must use. Unless, it is really doesn't differs
> > from JS, which in our time can be compiled from many NORMAL languages.
>
> I think you are slightly confused by what the spec is saying.
>
> " A declaration is private iff it begins with an underscore (the
> character) otherwise it is public. A
> declaration m is accessible to library L if m is declared in L or if m
> is public."
>
> m in this case is a variable name of a variable, not the literal
> character m. Just to reiterate clarification, if I say 'var myName',
> it is NOT private.
Keywords only appear at the declaration/definition site of variables whereas the "_" prefix is also visible at the use-sites. This simplifies the semantics and implementation (thus making it more robust).// florian
Keywords only appear at the declaration/definition site of variables whereas the "_" prefix is also visible at the use-sites.
The number of times you'll be bouncing around code to figure out if
something is public/private because you used a keyword will be far
greater than the number of times you had to find/replace a var's name
because you changed visibility later.
Besides, notepad, emacs and vim all have find/replace;
you're also
probably doing something wrong if you're unhiding a private member
variable...
I think the use of an appropriate type modifier such as "library" or "private" improves the readability of the declaration.
I'd prefer for the private variable not to be seen at all by the inheriting class; if accessed, it would be just like the variable was not yet declared. and since this was the case, (this may be an obvious implication) the same variable name can be re-declared by the inheriting class without affecting the parent class
And the same for the 'final' keyword: all variables are final unless explicitly declared with the 'var' keyword, like so:
So maybe >50% of all my identifiers will be _ prefixed, but this is just syntax and you get used to that pretty quick.
A more difficult question is what happens when I need to change (privacy) one way or another. That is going to involve a mass search and replace to occur would it not?
When reviewing older Java code I found that very often a final keyword could be added without harm.
I personally don't know what to think about this. I hate when names affect semantics, but in this case... it's just so very clear and simple, I even might start to like it :-)
>> Any IDE worth its salt can inform the developer of the accessibility
>> of such as they
>> view it ...
>
> A language should not be reliant on an IDE to be used efficiently.
+1. This is a clean-sheet language design - why bake in dependency on external tooling?
And the same for the 'final' keyword: all variables are final unless
explicitly declared with the 'var' keyword, like so:
String name = 'Bob';
var int age = 26;
name = 'Bill'; // error
age = age + 1; // Ok
agree. trailing_ is much easier on the eyes.
thanks
---
co-chair http://ocjug.org/
At 10:00 PM 1/13/2012, you wrote:
>I have got to say, looking at the dart code samples makes me want to
>cry. The underscores everywhere just destroys the readability of the
>code.agree. trailing_ is much easier on the eyes.
Mmm I like dart. Please don't make me feel like coding obj-C.... ;-)
Hi Brook.
I agree with you, it's an arbitrary character, but as arbitrary as any other.
I don't like the underscore either, but it is true that I would never have a public _field. And I also see that everybody uses it to name private fields, so, as a matter of convenience, I welcome it :-)
Look java, because of not having something like that it is a mess, not one, but n arbitrary chars! Some people use field1, others _field1 and a third slice uses mField1... (!!) It is a sacrifice I am willing to do avoid such a mess :-)
My two cents,
Kind regards,
Diego
Am 22.01.2012 14:17 schrieb "Brook Monroe" <brook....@gmail.com>:
Harsh words...
> It's an arbitrary character, meaningless in other languages,
... and wrong too. Surprisingly you are referring to python yourself, where even more than one underscore is part of the language.
It is significant in Haskell and also in Scala, both in the semantics of a placeholder (hmmm. More or less).
> and if
> one of the goals of Dart was to make a language that looked like
> something you're used to, then that's being flung down and danced
> upon.
Seems it depends on who is 'you' in the "you are used to" part, and if 'you' is willing to adapt anything new or only copying the "me like" style once more.
> Anyone trying to read Dart code for the first time without benefit of
> the tutorial is just going to think that the code author had a fetish
> about variable names;
In my experience anyone trying to read code in a language unknown to him will -without tutorial- be victim of misinterpretations, more or less, but not never. Depending on where you come from, Dart is boringly surpriseless or a big leap.
That is always true for any language.
> it wouldn't immediately be obvious that a given
> variable was public or private. Forcing scope by naming convention
> seems as feckless a choice to me as forcing logical subordination by
> indentation. (I'm lookin' at YOU, Python.)
Opinion.
> So, what about this as a choice?
>
> class A {
> private {
> this.var1 = ...
> this.var2 = ...
> }
> this.var3 = ... // Public by default
Hmmm. Looks interesting. Except for the cluttering this-dot prefix.
So you would also put private methods in there?
That looks like separating the class into two sections.
As private means library scoped in Dart, why not separate into two classes and make only one the public API?
Than we are back at the module export syntax discussion.
But: sometimes complaining with harsh words isn't enough. Perhaps -with a new language- one has to look at the problem in new ways.
My view: I do not like the underline as modifier very much. But the leading one seems better, as it can be seen as kind of a unary operator.
Adam, I haven't understood. You know that underscore in Dart is not simply a usage convention but a language inherent part? In this regard it is as explicit as any other solution.
Although I think "private" is more readable, FWIW.
I was quite confused some time ago by this thing: how about members of private classes? Are they private? It doesn't matter if no instances ever get outside of the library, but what about private classes that implement public interfaces and their instances get out of the library? Well, I was overthinking it and I had to experiment with it a little, but then it finally clicked into place: it is all just about the names.
> Both of these are easily solved by using an IDE.
and
> An IDE or the compiler can detect inappropriate access to methods/
> fields etc as the code is written or compiled (or even executed in
> checked mode or otherwise)
> Any IDE worth its salt can inform the developer of the accessibility
> of such as they
> view it ...
A language should not be reliant on an IDE to be used efficiently.
'When I use a word,' Humpty Dumpty said, in rather a scornful tone, 'it means just what I choose it to mean — neither more nor less.'
'The question is,' said Alice, 'whether you can make words mean so many different things.'
'The question is,' said Humpty Dumpty, 'which is to be master — that's all.'
// a.dartclass PrivateInA {private method() => 'inside A';}class PublicInA {method() => 'inside A';}// b.dart#import('a.dart');class FromB {private method() => 'inside B';}callMethod(obj) {obj.method();}main() {callMethod(new FromB());callMethod(new PrivateInA());callMethod(new PublicInA());}
// a.dartclass PrivateInA {_method() => 'inside A';}
// a.dartclass PrivateInA {$library_a$_method() => 'inside A';}
callMethod(obj) {obj.$library_b$_method();}
jbeall, Bob Nystrom just pointed out it's impossible to implement 'private' as a keyword. Unless you want to add that at call sites as well, that is.
The argument about how do you compile to javascript with privacy that isn't supported in javascript isn't an issue either. The privacy can be enforced during compilation and does not need to exist in the javascript version.
As such you should know better than to recklessly change a variable that you want to use as private, and can treat it as such.
If you can't trust yourself from inadvertently changing a value you shouldn't access, then one option is to make every class it's own library and import everything. I know there are some who prefer this method, though it's not for me personally.