1 2 Previous Next 15 Replies Latest reply on Mar 25, 2011 11:31 PM by jschellSomeoneStoleMyAlias Go to original post
      • 15. Re: suggestion: immutable collection interfaces
        844715 wrote:
        While in theory you could downcast it to a modifiable list, in practice you practically never will -- certainly not unintentionally. So a read-only view of someone's possibly modifiable structures is a common idiom, and it would be good if there was a formal
        way to express it, as there is in C/C++.
        That is the point though.

        There is two levels of protectionism.
        1. Someone attempts to deliberately circumvent the protection.
        2. Someone using it unintentionally in a way not intended.

        For the first you can't stop it.
        For the second that a many, many other ways that people can cause problems. And I certainly haven't seen any evidence that modifying something that shouldn't as showing as a problem in even some cases, much less in a significant way.
        I just feel much safer writing code that takes someone's (possibly mutable) structure, when I know that I can't change it by accident.
        Having spent a great deal of effort at one time on differentiating mutable versus non-mutable in the C++ code space my take is that it is just fluff.

        Can't ever recall it solving even one problem. Certainly do not recall ever running into a problem and thinking that immutable would have prevented it. Haven't found that in java nor C# either. Initially I missed const in java but I do not recall any problems in java because of that either.

        On the other hand the following all have a significant impact and all of them happen all the time.
        1. Code that completely ignores reasonable error scenarios.
        2. Incomplete testing
        3. No error scenario testing.
        1 2 Previous Next