4 ms·
> I could tell similar stories for other languages that I don’t like programming in. These languages include JavaScript, Go, Java, and C++. ... > The thing I
by yr_robot_master 2y ago
> I could tell similar stories for other languages that I don’t like programming in. These languages include JavaScript, Go, Java, and C++.
...
> The thing I hate about all of the languages I listed is their emphasis on mutation. When I call a function and pass it a list or object or whatever, I have no guarantees about that thing’s value when the function returns.
This is not true for C++, where the 'const' keyword allows you to disallow mutation. Perhaps the author would complain that this behavior isn't the default, but the functionality exists.
- trealira 2y agoThis compiles in C++: int foo(const int &x) { int &y { const_cast<int &>(x) }; y += 1; return y; } It may invoke undefined behavior if the original int was declared const, but this still compiles with no warnings on GCC with -Wall -Wextra. It may be really bad style, but not mutating const references is not enforced by the compiler. Hence you aren't guaranteed that your const references actually stay unmodified if you pass them to a function.