0

I'm new with functional programming but experienced enough with code to sense a false good idea/antipattern, and that may be the case: I'm not exactly sure what "immutability" means. Does the state of an object has to be frozen ? Or should the object ONLY behave as such ? In my case, I can make my object immutable OR implement some lazy resolving/cache. From an external point of view nothing should behave differently in any way. Yet the state of my object WILL change.

I can post code if you want me to but the questions seems not language specific enough to do, but I'm coding in Python.

  • 1
    Possible duplicate of [Immutable vs Mutable types](https://stackoverflow.com/questions/8056130/immutable-vs-mutable-types) – g_uint Jan 28 '19 at 06:57
  • An “immutable” object prohibits sanctioned mutations: eg. there are no setters or methods that update the state. A mutable object may still be “effectively immutable” based on usage. Just as in even a strongly typed language like C#, bypassing the contract as for example with reflection, should not imply an object is not “immutable”. – user2864740 Jan 28 '19 at 07:24

1 Answers1

0

Yes, a mutable object can be changed after it is created, and an immutable object can’t.
Python handles mutable and immutable objects differently.
Specifically for Python, I found an interesting post on medium.com

Amey Chavan
  • 1
  • 1
  • 3
  • That article contains suspect information along with good information. For starters, Python treats mutable and immutable objects the same - it is simply that an immutable object cannot be changed and thus all variable updates require a new object to be assigned in the immutable case, naught else. – user2864740 Jan 28 '19 at 07:17
  • I'm familiar with python immutability, rather than implementation, my question was more on the conceptual/pattern aspect, specifically in respect of functional programming. – QuantumPotatoe Jan 28 '19 at 08:16