Hi, On 18/02/11 10:49 AM, openbala wrote: > The gist of immutability is that any operations on a data structure > should not change its data structure. (for e.g. java's String class is > immutable)
But the List implementations (LinkedList and Vector for example) in Java are mutable. So are List implementations in C++ STL. > The general consensus is that mutability is bad for programming. YMMV. Any data-structure that goes beyond the simplicity of a String must be mutable irrespective of the programming language (of course with some possible exceptions). If lists were not mutable, how would you insert, remove or modify an element in a list ? The very purpose of using a list is to allow someone to add, remove or update elements on it right ? Coming back to the original context where list.reverse() modified the original list, there is also reversed(list) function that returns a list iterator that allow you to traverse a list in reverse order without modifying the original list - right design for the right purpose :-) Cheers, Chandrashekar. -- http://www.chandrashekar.info/ http://www.slashprog.com/ _______________________________________________ ILUGC Mailing List: http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
