ImmutabilityBeatsDataHiding
ThoughtStorms Wiki
Context : ImmutabilityInProgrammingLanguages
If you want to sum up the ObjectOriented vs FunctionalProgramming debate in a nutshell.
Immutability (the FP ideal) is better than mere DataHiding to make your code easy to manage, maintain and change.
Data hiding means you don't know what's in the black-box. But this doesn't guarantee that it might not come out and bite you. (LeakyAbstraction)
Quora Answer : Are programs written in functional programming languages easier to change than imperative ones?
Having been dabbling with FP for a few years, I'm sold on something that I didn't previously believe : immutability is a good thing.
I used to think that immutability was a kind of unnecessary fussy, fastidious idea. Rather like some of the other disciplines that OO people banged on about. Eg. keep data private (I never had a problem with no privacy in Python, just don't mess around with other people's insides. What's the problem?) What was wrong with a bit of state when it's convenient?
But today, I'm convinced. Thinking of algorithms without state. Especially when the language supports / insists on it, makes your life easier.
I don't normally like to feel controlled by my language. But I welcome a language that obliges me to restrict mutability to specific places and mechanisms.
So to the extent that FP has brought this idea mainstream, and FP languages restrict state, I think they have the advantage over OO languages like Python and Java. Having no mutable state at all is a far better, more robust solution to losing track of state than the OO solution of just encapsulating and hiding it.
Backlinks (2 items)