3 ms·
There is a huge loss in usefulness for immutable objects when immutability is not a default and you have that many different implementations. The thing I like
by setzer22 9y ago
There is a huge loss in usefulness for immutable objects when immutability is not a default and you have that many different implementations.
The thing I like about immutability in languages that implement it by design is that you know that if you get an data structure, it is immutable. In the world of javascript, you not only have to worry about whether an object you get from a library is immutable, but which kind of immutable implementation is using. Moreover, that information is not easily available in the type signatures, so you have to go to the library author's documentation, if any! That, to me, is a complete mess.
- Rotareti 9y agoI totally agree with you. I wish we had a built-in immutable array type and a built-in immutable object type. I love the way it's done in Python, where you have Lists vs Tuples and Class Objects vs NamedTuples. You can consume them the same way: my_list = [1,2,3] # mutable my_tuple = (1,2,3) # immutable my_clsobj = myclass(foo=1, bar=2) # mutable my_namedt = mynamedt(foo=1, bar=2) # immutable my_list[0] # 1 my_tuple[0] # 1 my_clsobj.foo # 1 my_namedt.foo # 1
- macintux 9y agoMore generally, this is why I don't find languages that add "functional" features very compelling. Behavior is so well-defined in a functional system that it's intensely frustrating dealing with any imperative/OO language.