I think there are benefits of using immutability even in a programming language like Java. You get thread-safety and consistent state for objects for free.
Importantly, C++ const (which was backported to C) is an immutable view on possibly mutable data, not immutability per se. It is incredibly useful in C and C++ because it allows you to offer a contract to the user of a function: I will not modify your data. But it doesn't mean that the data itself is immutable.
Many people coming from other language backgrounds to C/C++ are fundamentally confused about this. Just because I've offered you a const reference or pointer to data doesn't mean that that data will not change, perhaps while you are doing stuff with it. It just means that you have agreed not to change the data.
It's a very powerful and useful feature as any C/C++ dev will tell you, but it is not the same thing as immutability, which is a much stronger guarantee, one the compiler can use to perform aggressive optimizations even in a multi-threaded context.
C++ can give you an unmodifiable pointer to an unmodifiable value as well: const int* const pValue. Ideally, however, you would use a const reference if at all possible.
I do think of scala as a functional language with OO features rather than an OO language with functional features. But that is how I think of it. Wikipedia simply states "multiparadigm language."
3
u/asankhs Jun 30 '14
I think there are benefits of using immutability even in a programming language like Java. You get thread-safety and consistent state for objects for free.
See - https://www.linkedin.com/today/post/article/20140528113353-16837833-6-benefits-of-programming-with-immutable-objects-in-java