I just watched the video by Barbara Liskov. He references this to show how even a turing award winner does not like FP.
The only thing that I would directly releate to FP was that she: "I think programms are fundamentally about manipulating state". Therefore she did not like the FP back in the 70s.
So I will try to show that thats a very bad reference.
1. Today FP languages are mostly about only using state if there really is state not like in OO where you just use state everywhere.
2. Try to be more clear where the sideeffects happen --> dont interleave the sideeffects with the computation. In Haskell you even have to be explicit where you use sideeffects.
in imperative (in VB)
for i = 1 to 100
print computeSomething(i)
next
while in FP you would
(print (map computeSomething (range 1 101))
(I know that thats not 100% the same output but I hope you get the point)
3. She was doing Systems Programming for the last 30 years an yes at that level there is lots of state but at a high level there does not need to be that much state INSIDE the programm.
More generally speaking:
All the typical OO features FP languages can provied. For example Hierarchy are totally interleaved with the rest of the programm. In Clojure you can use Hierarchy if you really need a kind of animal -> dog Hierarchy-System. Even better because its not interleaved you can have two Hierarchy-System on the same "object" without them disturbing each other. The same with Polymorphism.
I think saying that FP is bad for "manipulating state" is misleading.
FP is great at manipulating state. A pure Haskell function (State -> State) manipulates state.
What's being discussed is whether or not the state is manipulated destructively. And personally I don't see any real benefits to the destructive method, except performance issues in some cases, and arguably stylistic ones.
Returning new values instead of in-place updates may seem cumbersome before you get to know the abstractions that make it easy to use.
As an example, in Haskell, if you want to update a value deep inside multiple nested records, you do something like:
movePlayer :: (Pos -> Pos) -> GameState -> GameState
movePlayer f gs = gs { player = oldPlayer { position = f oldPos } }
where
oldPlayer = player gs
oldPos = position oldPlayer
movePlayer :: (Pos -> Pos) -> GameState -> GameState
movePlayer f = (atPlayer . atPosition) f
or just:
movePlayer = atPlayer . atPosition
Then you can use:
movePlayer (+delta)
to add delta to the position.
Now one nice thing about the return-new-value approach is that it is more composable than the destructive update approach. When you compose state manipulation functions, you get transactional state changes.
So paradoxically, I believe functional languages to be better at manipulating state!
The only thing that I would directly releate to FP was that she: "I think programms are fundamentally about manipulating state". Therefore she did not like the FP back in the 70s.
So I will try to show that thats a very bad reference.
1. Today FP languages are mostly about only using state if there really is state not like in OO where you just use state everywhere.
2. Try to be more clear where the sideeffects happen --> dont interleave the sideeffects with the computation. In Haskell you even have to be explicit where you use sideeffects.
in imperative (in VB)
for i = 1 to 100
nextwhile in FP you would
(print (map computeSomething (range 1 101))
(I know that thats not 100% the same output but I hope you get the point)
3. She was doing Systems Programming for the last 30 years an yes at that level there is lots of state but at a high level there does not need to be that much state INSIDE the programm.
More generally speaking:
All the typical OO features FP languages can provied. For example Hierarchy are totally interleaved with the rest of the programm. In Clojure you can use Hierarchy if you really need a kind of animal -> dog Hierarchy-System. Even better because its not interleaved you can have two Hierarchy-System on the same "object" without them disturbing each other. The same with Polymorphism.
http://clojure.org/multimethods
I don't want to say OO is very bad I like just like the decision CMU takes here. Teach these concepts sepertly and not in a language like Java.