I prefer using single assignment variables when possible. I find myself not doing this simply because littering the code with "final" looks much worse than "var." Can we get a more terse single assignment keyword?
I believe final should be the default. Like many things I believe, we don't see the world quite ready for that. Likewise some new-fangled word instead of final ('val' anyone?).
I believe final should be the default. Like many things I believe, we don't see the world quite ready for that. Likewise some new-fangled word instead of final ('val' anyone?).
Depends on what you mean by "killer".
You proposed some weird characters in other threads too.
Due to the fact that my Android phone does not display those characters (they are all shown as rectangle), this indeed "killed" the code you show.
Back to topic: I am absolutely for default final, resp. "val". I am used to it from Scala too. But I always wished Scala had chosen 'let' instead of val, because on one hand it reads better in a mathematical sense ("let a be the result of ...") and is better distinguished from 'var' at a glance.
So if EcmaScript 6 let keyword semantics is not an argument to stay away from using 'let' in Dart, I would prefer that one.
KR
Det
final can be replaced with fix,
to indicated that the binding is fixed.
Am 02.03.2013 09:13 schrieb "Aza Tek" <aza...@gmail.com>:
>
> final can be replaced with fix,
> to indicated that the binding is fixed.
That would afaic intoduce a completely new terminus, never seen elsewhere before, while 'final' is already a known keyword from Java, 'val' a known keyword from Scala, Kotlin and ML, 'let' a known keyword from different languages including Roy, EcmaScript 6, Haskell, ML again - although with different semantics in each.
I would still prefer 'let' over 'val', assuming Dart will never have a 'let .... in ....' construct.
> final can be replaced with fix,
> to indicate that the binding is fixed.
That would afaic intoduce a completely new terminus, never seen elsewhere before,
I believe final should be the default. Like many things I believe, we don't see the world quite ready for that.
I believe final should be the default.
Like many things I believe, we don't see the world quite ready for that.
Likewise some new-fangled word instead of final ('val' anyone?).
On Sat, Mar 2, 2013 at 12:38 AM, Gilad Bracha <gbr...@google.com> wrote:
> I believe final should be the default.
It would really help, can't we add an option to implicitly declare
everything final?
Likewise some new-fangled word instead of final ('val' anyone?).I have never liked val, as it's too similar to var. Which, for someone, is an advantage instead of disadvantage. I'd personally prefer def.
I have never liked val, as it's too similar to var. Which, for someone, is an advantage instead of disadvantage. I'd personally prefer def.I would vote against def, because
a) in Groovy def is used to define variables and methods/functions alike,and is only used to omit the return type (somehow like var in Dart currently). It has nothing to do with readonly access.
b) in Scala def is used to define particularly methods/functions, or better "values that are recalculated on each access". So they are indeed not "reassignable", but have a totally different semantic to val, which also exists. There is a concept around def vs. val, saying that you can replace val with a parameterless def and vice versa without changing the caller.
But from an implementor's view the effect is different.c) Python uses the def keyword explicitly to define functions.d) Ruby uses the def keyword explicitly to define methods.
So far, def is the second worst keyword to use here, after final, imho.
You can always find counterexamples.
For example, EcmaScript 6 uses let as a sort of replacement of var, fixing the scoping rules.
So let is a no go.
LT
--
That is use
var x := 1; \\ or
int x := 1;
for an immutable binding. This way all existing code continues to work, and final bindings can be created without much trouble.
I'd also love final as default but I know it will never happen. I was wondering if the dart formatter could have an option to automatically replace var with final if it's applicable.
--
Just curious: if you make final a default, how would you declare non-final?
Just curious: if you make final a default, how would you declare non-final?That is one more reason we didn't go that way. You need a keyword that indicates that something is mutable. Hard to find something familiar/short/attractive.mutable x;x = 3;
how about:let x = 3; // immutable
int x = 3; // immutable
var x = 3; // mutablevar int x = 3; // mutable
-g.
I notice in the other thread which was referenced that Gilad mentioned that a separate assignment operator wasn't an option? Was it because it is not a construct that is used in other languages and as such not something familiar to someone new to Dart who may see it used?
Making everything final by default is really risky, but adding a backtick synonymous with final is not IMO.
so instead of
final int i=0;
you write
int `i=0;
then we will be really barking a wrong tree and just waste good symbol (really VERY valuable one).
I've never seen the proof that meticulous use of "final" translates to significant reduction of bugs, I personally very much doubt it, but it's a good "selling point" - simply because many people believe so.
then we will be really barking a wrong tree and just waste good symbol (really VERY valuable one).
I've never seen the proof that meticulous use of "final" translates to significant reduction of bugs, I personally very much doubt it, but it's a good "selling point" - simply because many people believe so.These are both entirely subjective statements. I think your opinion of a backtick operator is clearly in the minority. That being said, you've made your case for it, why the need to practically hijack the thread trying to convince people that a backtick operator would be great (or some other weird unicode character, for that matter)?
> it has never been used or considered before for assignment or immutability - for good reason
> var! a = 10;
Ruby:
foo = "A STRING" # a string called foo
foo.downcase! # modifies foo itself
puts foo # prints modified foo
> This thread started (post#3) with the following statement by Gilad:
>
> > I believe final should be the default.
>
> Then, after intensive exchange of mostly untenable suggestions that don't make the slightest sense (but supposedly were not humorous!), out of nowhere, came two ideas:
> 1) exclamation mark
> 2) all capitals
Here's my personal wish: I don't want Dart to add a lot of punctuation. I think I would tolerate it in type annotations, should we get any new (function types, union types, nullable types), but that would be pretty much it. I would hate punctuation for declaring variables final -- and in the end, I don't think it's crucial for Dart to have final by default.
(For what it's worth, I'd much rather have the ability to declare classes final so that they can't be subclassed!)
LT
> At the same time, backtick is a rare symbol that doesn't hurt readability
Except that there is a bunch of fonts out there where the backtick glyph looks similar to the apostrophe glyph. (And what's worse, there is a lot of people that use these two characters interchangeably. I think that backticks will never be given any meaning in Dart.)
LT
Am 05.03.2013 04:33 schrieb "Alex Tatumizer" <tatu...@gmail.com>:
>
> Unfortunately, in year 2013, we are still limited to the same set of characters as in 1950. No umbrellas, no skulls, no bold, no color.
> Why? I don't know. I don't think there's any technical reason for this.
I do!
It is the fact that a standard keyboard has a limited set of (what? 104?) keys with a much more limited set of internationally overlapping characters. Keyboards are mainly used to write text beside code.
I do not want to install and learn a very special keyboard layout only to write one specific prog-lang's code.
And when I write code on different devices and OSes I do not want to research first the best way to input some unicode character.
Although I sometimes find e.g. functional code written with single character arrows (thin and fat) and a correct lambda sign intriguing, I cannot imagine to maintain a really large code base full of special signs.
It makes keyboard input ineffective.
E.g. the decision of architectureWare to use guillemets in their template code was a really bad choice outside of France.On a german keyboard on windows you end up with endless Alt+0xxx on num block. Don't even know how to do on linux, not to mention my smart phone.
So: Yes, it looks intriguing first, but is not practicable in large. Please stop proposing special unicode signs for international coding.
KR
Det
All in support for Lad (regarding punctuation and backticks), except
Am 05.03.2013 06:00 schrieb "Ladislav Thon" <lad...@gmail.com>:
> and in the end, I don't think it's crucial for Dart to have final by default.
>
> (For what it's worth, I'd much rather have the ability to declare classes final so that they can't be subclassed!)
>
The need to declare classes final comes not so often to me.
The wish to declare objects immutable very often. This is done by declaring all attributes final.
Often enough when reviewing code I wish Java had final as default too, seeing weird code structure or even runtime errors due to reckless variable reuse.
This is solved by declaring local variables final.
Altogether this follows Effective Java Item 15 "minimize mutability", (beside the fact that it is considered good style in Scala and enforced by Haskell for good reasons).
KR
Det
Am 05.03.2013 06:30 schrieb "Alex Tatumizer" <tatu...@gmail.com>:
>
> And you editor doesn't support setting up some CTRL/something for this? Strange.
>
You haven't understood: I don't want to make coding in a PL depending on features a certain editor(*) may have!
Some code in a certain language must be writable everywhere.
I do not further discuss this topic.
(*) which ranges from a full blown IDE over UltraEdit, vim in a terminal window, over some office word processor over an email program down to a simple online chat input field.
> The need to declare classes final comes not so often to me.
> The wish to declare objects immutable very often.
Preventing subclassing is actually a part of that.
But then, with the ability to implement an implicit interface of each class, almost all guarantees are pretty weak. If you accept instances of your library class from the outside, you can never be sure if it really is an instance of your class.
(Asking for a way to prevent subclassing should probably mean that I also ask for a way to prevent implementing the implicit interface. I'm not sure about that.)
LT
That is one more reason we didn't go that way. You need a keyword that indicates that something is mutable. Hard to find something familiar/short/attractive.
out of nowhere, came two ideas:
1) exclamation mark
Looking at what others are doing there was a C# proposal for using a '!' suffix:
http://twistedoakstudios.com/blog/Post330_non-nullable-types-vs-c-fixing-the-billion-dollar-mistake
The annotations for the closure compiler use the '!' as a prefix:
https://developers.google.com/closure/compiler/docs/js-for-compiler
int x = 3; // immutableThis would be a backwards incompatible change. And would stand to break a fair amount of code.
var x = 3; // mutablevar int x = 3; // mutableThe latter of which I'm not a fan of, too many key words to declare a statically checked variable.
int x = 3; // immutableThis would be a backwards incompatible change. And would stand to break a fair amount of code.Backwards incompatible changes happen all the time in the current version of Dart.
Am 05.03.2013 07:23 schrieb "Ladislav Thon" <lad...@gmail.com>:
>
> > The need to declare classes final comes not so often to me.
> > The wish to declare objects immutable very often.
>
> Preventing subclassing is actually a part of that.
Not for my intention so far, but interesting point!
I'll think about it.
>> But then, with the ability to implement an implicit interface of each class, almost all guarantees are pretty weak. If you accept instances of your library class from the outside, you can never be sure if it really is an instance of your class.
>
Well, that is your concern about subclassing, and was so far no problem for me as I did not look at the behaviour but the value.
Let them subclass, as how they use my lib is their responsibility.
My concerns are more the other direction:
Ensure that instances (values) a lib gives away aren't changed outside, avoiding side effects leaking back into the lib.
This may even be a lib internal concern, if we think about async/parallel/concurrent processing.
> (Asking for a way to prevent subclassing should probably mean that I also ask for a way to prevent implementing the implicit interface. I'm not sure about that.)
Regarding that this problem can only manifest itself on the boundaries where instances are exchanged, I cannot see what real necessity exists for avoiding subclasses.
If a class' implementation is absolutely vulnerable, it should not be part of the boundary, not participate in the exchange.
This may not be achievable in all cases, but this design rule reduces the cases where it is a problem to the minimum.
You can't reduce data exchange the same way. Thus value objects should default to immutable, i.e. attributes are final.
KR
Det
Am 06.03.2013 05:53 schrieb "Alex Tatumizer" <tatu...@gmail.com>:
>
> There's a palliative solution - not sure it makes sense, but there's a chance.:
> The idea is:
> 1. if variable is provably final(*), treat it as final (even if not explicitly declared as such)
Sorry I don't see the sense here. What means "treat it as final"?
Final is not a result of some analysis but an intention communicated to the analyser.
In your case, if someone assigns to the variable, compiler would simply not see it as final anymore, so what?
It can't decide if this is by intention or a bug.
If OTOH the developer explicitly or the spec implicitly defines a certain variable as final, analyser would show an error when he detects a reassignment. And that is part of "treat it as final" for me.
> 2. In the editor, use different highlighting styles for final (no matter explicitly or implicitly) and non-final variable names (at the point of declaration).
> 3. Use "brighter" style for non-final vars, allegedly to draw attention to them, with a hidden goal to motivate programmer to consider making it provably final.
Sorry, but consistency check should be done by the analyser/compiler, not per optical control by a developer sitting in front of a necessarily full fledged IDE.
>
> (*) notion of "provably final" is TBD. but roughly it means:
> - it could be declared final - compiler doesn't see any problem with that
> - compiler is sure that application has no way to modify the variable other than via reflection. E.g., public instance members cannot be provably final.
>
Right. But especially here final plays its useful role!
> Again, I'm not sure it's a tenable idea;
I don't see how it is. So please don't post such ideas prematurely.
> In your case, if someone assigns to the variable, compiler would simply not see it as final anymore, so what?Yes, highlighting will change, that's it. That's all compiler can do. "Treat it as final" means "for the purposes of highlighting".
> It can't decide if this is by intention or a bug.
That's the best this editor can do to show you which vars are factually final, and which are not. What syntax highlighting is about? Visual help.
> So please don't post such ideas prematurely.This is not a polite expression. You could say "meaningful, but not convincingly" or something to that effect.
If it doesn't make sense to you, just say so, without issuing comical commands.
@Dirk: believe you or not, dart editor already tries to highlight initialized variables differently (though not consistently).
Backwards incompatible changes happen all the time in the current version of Dart.var x = 3; // mutablevar int x = 3; // mutableThe latter of which I'm not a fan of, too many key words to declare a statically checked variable.That's the point, mutable should be inconvenient instead of the other way around (i.e. final int x = 3).
You're going to get comments regardless of what verbage the language uses. However keeping it familiar will help bring Java developers to dart. I see no reason that dart should set such a massive breaking change now for the sake of two characters, which will make the language less familiar to those coming from java, c#, etc.
That's it though. People with any taste have move on from Java and even C#.
... I'm sympathetic, but the rest of the population, the untold masses with no taste, who are still writing a ton of Java and C#, and will need an outlet for that experience when their employers are finally comfortable moving them into web development... queue Dart, which they'll pick up in an afternoon, thus remaining in good favor with the boss because they will have saved their fretting manager thousands and thousands of dollars in retraining expenses. (Oh yeah... it's fast, and can produce high quality, professional, code, to boot.)
Dart is almost pre-determined to offend many early adopters because it intentionally draws from the conventional while the early adopters are drawn to the unconventional.
I prefer using single assignment variables when possible. I find myself not doing this simply because littering the code with "final" looks much worse than "var." Can we get a more terse single assignment keyword?
New keywords can be learned or forgotten in few seconds.
But there is no way an average Javascript and mabye even Java programmer learns the serious stuff and the subtle differences of Dart in 24 hours.
> Point p = new Point(0,0); // good grief. 1995.
> val p = Point(0,0); // This looks like a language for 2013 and beyond for building modern structured Web Apps with Web Components!
1995: Point p = new Point(0, 0);
2005: p = Point 0, 0
2015: val p = Point(0, 0);
Really?
LT
Hmm java devs have GWT. We try Dart cuz it's Dart not because it's better than Java
the final keyword is acceptted consider the familiar of final, because it's not redundant keyword, people just want a shorter form keyword, but the new keyword is really redundant, its comes with no benefit except makes dart looks like Java or other static typed language, i am wonder what's kind of reason not drop 'new', it's possible some kinds of software engineering reason, but i don't gotcha that
If the compiler is not "stupid" then this is normal.void main () {final int i;if (true) {i = 0;} Else {i = 1;}print (i);}Dart compiler (I think) more like 'stupid'.Even it compile at runtime ...Because if you run script in "checked" compiler MUST compile all code paths and analyze code statically before executing.--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
2005: p = Point 0, 0