-
-
Notifications
You must be signed in to change notification settings - Fork 661
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 final keyword #6584
Comments
|
wat? |
Why not e.g. I'm curious what "that toString thing @back2dos was talking about in the bar" actually is? :) @jdonaldson pun intended! :D |
|
On a personal level, and having experience Const Hell In cpp, I can't say I am thrilled about this. As long as we don't have it in parameters and return types, it's ok to me. |
It's about references, not types. |
Ok to me then! |
Well, I would argue about that. It certainly has a meaning! See https://stackoverflow.com/questions/37916940/why-was-the-name-let-chosen-for-block-scoped-variable-declarations-in-javascria. I'm not a kind of a person who fights for every additional character typed on a keyboard but since this is a completely new keyword/feature, why not make it concise from the get-go? Whatever you choose, please have it already! :) Btw. there's also Scala's |
I'm really used to 'const' everywhere in JS (with the same semantics) excepted when mutable. But I'm not looking forward to adding 'final everywhere :( |
I don't want to add a keyword before 'var'. I don't even care about making classes and functions non-overridable. I'm not looking to coding in Java. Sorry for being negative though, it's still progress to come. |
I think |
Actually what we discussed was |
That's a bit better, but still has different meanings for classes/methods and vars. |
For me seeing |
Can we say that objecting that it can confuse C++ devs is moot?
|
|
|
In Scala there's |
Can't we all agree that |
I propose var x, but using an unicode non breaking space between "var" and
"x" to distinguish if it's mutable or not.
…On Mon, Sep 18, 2017 at 5:37 PM, Cauê Waneck ***@***.***> wrote:
Can't we all agree that final conveys what we want without it being
confusing?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6584 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA-bwP4pXY672CPdlUXNSckwD3rCF2Jfks5sjo4cgaJpZM4PZ2mV>
.
|
LoL
I agree with Danny "val" seems good as it's the same length as "var" so
your variables still line up when you change one to mutable. Final is
just going to confuse a lot of users it just feels wrong. const if it
confuses c/c++ programmers is probably a good enough reason for using
"val", plus it's longer.
Surely 'val' is nice and sweet and to the point, my only worry is the
same first letter could allow people to mistake it for var, but var for
variable and val for value seems very logical and easy to explain.
…On 18/09/2017 16:39, Nicolas Cannasse wrote:
I propose var x, but using an unicode non breaking space between "var" and
"x" to distinguish if it's mutable or not.
On Mon, Sep 18, 2017 at 5:37 PM, Cauê Waneck ***@***.***>
wrote:
> Can't we all agree that final conveys what we want without it being
> confusing?
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
>
<#6584 (comment)>,
> or mute the thread
>
<https://github.com/notifications/unsubscribe-auth/AA-bwP4pXY672CPdlUXNSckwD3rCF2Jfks5sjo4cgaJpZM4PZ2mV>
> .
>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#6584 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAd388KBCBiyU0EtoHUURGDdwJc_SMgTks5sjo67gaJpZM4PZ2mV>.
|
I don't like val because it looks like var and doesn't mean anything. We can find pros and cons for any suggestions, so I'll just go with the original one. Can't make everyone happy anyway. You all will be happy once you realize we can do |
Currently it is very difficult to get Haxe generated code fully thread safe on Java and C# targets, specifically around var initialization within constructors. If this proposal means vars with 'final' are expressed in Java and C# targets with their language equivalents I believe we would finally have the tools needed to make truly thread safe code without crazy hacks. Not sure if that is the intention. |
As a side note, it would be trivial to make "val" look distinct from "var" via code highlighting rules in an editor. |
I don't really see much benefit from having final locals in general, but I also think Final class fields would cover a lot of cases where you'd want to have As for the classes and functions, I would suggest having it inverted: everything is non-overridable and you can mark things explicitly overridable. I think that's a bit cleaner and stricter, but I don't have a strong opinion on that (and I know that this is unlikely to be changed as it's too breaking). On a related note, I think we should have an optimization filter that makes classes/functions |
No
Yes |
Uhm, var doesn't mean anything either. var = variable Code lining up and having the best option ( Never had any problems distinguishing both in scala code ... and this was 6 years ago already. def something : Int = 1
var someother = 2
val someaethe = 3 |
But allowing |
What if I told you, typing |
It won't because Btw. is it possible to start working on this feature and decide on a keyword only when it's being merged into the main branch? I mean it's a bit pointless arguing about a keyword while I'm sure more interesting problems will emerge when implementing it. :) Btw. no 2: @back2dos what was that |
Teach your IDE to insert a space when auto completing |
Because y'all just love it when I go on lengthy rants, I prepared a very special piece for you titled: I want to be able to name stuff and in 2017 Haxe does not provide a proper way to do thatIn opening, a few words chosen with utmost care to depict as accurately as I can my view regarding the status quo in this particular matter: it's an effing disgrace. I don't know how you cannot see that something so fundamental is just entirely broken, so please excuse me if I'm stating the obvious at any point. I simply cannot figure out which part of this escapes you. Naming should be the simplest thing to do in a programming language, and in Haxe it's impossible to do for values. And no, declaring a variable is not the same as actually naming a value. For those who don't understand such a simple notion, let me exemplify it: you cannot assign a different type to a typedef, you can assign a different value to a variable. There you go. Ain't no rocket science. Extending the matter a little further, it should be trivial to:
One way to achieve this would be to have "something like" standard ML's (I'm basically done here. What follows is only as relevant as are the weird twists and turns this discussion is taking. Feel free to ignore it.) On a side note: it's idiotic that all of us should pay the price for questionable design decisions in C++, just because some of us have apparently suffered horrible trauma from it. I feel very sorry for you and all that, but I don't see why we should all be made to pay for it indefinitely. In the words of Dijkstra:
There may be good reasons not to use On another side note: On yet another side note: About the "toString thing from the bar": the broader the type, the less one should write (I require less, so I specify less). You will see that this largely holds in Haxe already: class Test {
static function print(o:{ toString:Void->String })
trace(o.toString());
static function main()
print("Haxe is great!");//will not compile for totally obvious reasons
} It should be really easy to describe the structure of something I wish to consume, but not mutate. If I have no intention of mutating the argument's value, I must go out of my way to specify it per To summarize: a readonly type is a broader type than its readwrite counterpart (as evidenced by variance) and the broader the type, the less one should write. I'll let everyone draw their own conclusion. There is something to be said about the future of computing being parallel and therefore immutability becoming very important. But really, I don't care about the use cases, as much as I care about one simple thing: reducing cognitive burden. When I see an identifier being declared and I can assume it won't change, then that's great. It's just so much easier to reason about the code. I don't want to keep stuff in my head. That's what I use a compiler for. Example: when I refer to Simn, I want to know that I get that particular guy. There's a very real risk that his mood degrades between the two points in time that I retrieve the value, because of me annoying him too much in between, but it's going to be the very same Simn. Not a bearded Simn from an evil parallel universe or anything else. That's one less thing to worry about. And trust me, if you have projects in production for +5 years or quite simply have a team of +15 haxers, then all these benign problems do add up to a death by 1000 cuts. Similarly I would argue that function arguments and variables captured in pattern matching should not be mutable - interestingly for loop variables we can enforce such a thing and rest assured, that's not because it's impossible make mutable loop variables without breaking the loop - in fact Rest assured: Haxe has things backwards on that subject and it matters. People are doing quite desperate things to escape this madness. All this may easily seem like pointless bitching if you either don't use Haxe in production or you have your little indie studio with barely a hand full of haxers of whom at least one is a freaking genius who by the way can just change the language whenever he pleases. I can only hope that this is not the intended way to use Haxe out in the field. If so, we should include an adequate warning. There's all this talk about simplicity, and we can't even have the simplest things. Please change that. Thanks. |
👍 |
You know, I really like the part where you try to be smart and it hinges on you quoting part of what I say out of context. It's not only an admirable display of intellectual prowess and a great example of how to participate in argument. Much rather it stands as an example of the type of leadership Haxe needs and I can already see how it will make selling the technology to more companies much easier. You should really be proud of yourself. Bravo! |
Hey Juraj, don't be offended and I apologize if you felt this way. |
So what ? Should we vote between final and const ? |
My understanding is that what is being proposed (and has been merged) is |
I think that |
You can't redeclare a class method So should you be able to redeclare a I like how in Golang you can't redeclare vars in the same context easily, and how it's a nice way to catch many beginner mistakes and reduce unreadable code. This holds especially true when going through a file that has the same property name defined in the class, in multiple method calls, and in block contexts 4+ times - making debugging of it super-hard... |
Too bad variable means "Likely to change or vary; subject to variation; changeable" |
I guess what should be noted in the docs - since it might be unexpected for js users of class Main {
static final a : Int = 123;
static function main() {
trace(a); // 123
Reflect.setProperty(Main, "a", 124);
trace(a); // 124
var a = 125;
trace(a); // 125
}
} |
* support `final class` see #6584 * fix parsing so it allows both `extern final` and `final extern` Also hold back on the warnings because the Flash API has `@:final` everywhere * properly represent final fields as `cf_final` * add missing isExtern on ClassField * fix extends display handling of final classes * ctrl s * annoying * don't require inits for extern final fields * don't check for final inits on interfaces * don't lose final on structure type fields
|
final ident
at both field and expression level. Allows assigning to a field exactly once (per branch? probably...)final class
to forbid extendingfinal function
to forbid overridingThe text was updated successfully, but these errors were encountered: