←back to thread

498 points azhenley | 7 comments | | HN request time: 0.56s | source | bottom
1. shmerl ◴[] No.45768080[source]
Proposing making immutable by default in C or C++ doesn't make sense due to backwards compatibility reasons. New languages like Rust have easier time making better choices with immutable by default.
replies(4): >>45768149 #>>45768408 #>>45771014 #>>45773596 #
2. loeg ◴[] No.45768149[source]
cpp2/cfront could plausibly do this, right? Except he doesn't want to:

https://github.com/hsutter/cppfront/wiki/Design-note%3A-cons...

replies(1): >>45768185 #
3. shmerl ◴[] No.45768185[source]
Well, if they are willing to break backwards compatibility, a lot of things can be improved, including this.
4. NathanaelRea ◴[] No.45768408[source]
They could just add a "use immutable;" directive that you place at the top of your file.
replies(1): >>45768453 #
5. Pxtl ◴[] No.45768453[source]
C# does this with the null hole. I wish more languages would take a versioning approach to defaults at the file-level.
6. JonChesterfield ◴[] No.45771014[source]
Could be a compiler flag. -const-by-default. Would probably mean you need to scatter mutable across the codebase to get it to compile, but I expect some people would like to have every local annotated as const or mutable.
7. _flux ◴[] No.45773596[source]
Maybe the new C++ profiles that are supposedly going to make C++ a safe language could do it.