-
Notifications
You must be signed in to change notification settings - Fork 259
Discussion: variables const by default #25
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
Comments
The Swift language has two keywords,
What's also nice is that you get warnings when you declare something as a non-const I get the impression from Herb's talk that he's all about post-fix declarations for everything, but I would hope if he were to do "everything const" kind of decorator / keyword, that it would come first rather than attached to the type. |
Personally I really like I also would prefer keywords for introducing new variables, I found lack of them jarring as it initially looked like introducing new variable is the same as assigning to existing one, though the |
That's way too similar. I don't like |
Rust has much better approach with |
Sorry to be that guy but the whole "experiment" with new c++ syntax is rather pointless. |
That viewpoint reflects a lack of knowledge of how the semantics of both languages differ, as well as a misunderstanding of the purpose of this project. But even in a hypothetical scenario in which the languages were semantically the same, the enormous inertia of usage of C++ compared to Rust would make "copying the new syntax over" worthwhile. |
I have seen a similar syntax that uses '=' and ':' to differentiate const and non-const: x : int = 5; // Mutable
x2 := 5; // Mutable
y : int : 5; // Constant
y2 :: 5; // Constant I think this type of syntax would be more ergonomic in comparison to requiring the "mutable" keyword everywhere. Additionally, making every variable constant would have some implications on backwards compatibility that this sort of syntax elegantly skirts. Alternatively, this type of syntax would add a new teaching point to the language, namely: use ':' over '=' unless you really need the variable to be mutable, which could be argued as being antithetical to this experiment's goals. |
As for me, it is unreadable ... num: int = 0; // Immutable
num := 0; // Immutable
num: mut int = 0; // Mutable
num : mut = 0; // Mutable |
I mostly agree with |
From my practice developers usually forget to add Adding
|
Const by default everywhere has the issue of inhibiting move semantics which can be a major performance issue. |
It should be possible to respecify how move semantics work in a Cpp2 with |
Have you considered making variables const by default? I have seen it float around as a recommendation and personally am of the "const everything" camp. It encourages more careful code, catches many errors and makes it more readable (if I see same variable later down the line, I know it has the same value, don't need to check every line in between).
The text was updated successfully, but these errors were encountered: