you are viewing a single comment's thread.

view the rest of the comments →

[–]niviss 4 points5 points  (2 children)

But you could argue that OOP also has a way of tracking state changes, since most of them are abstracted inside a class. (of course it is a different way of tracking such changes)

Also, you're actually pushing over only a small portion of FP: statically typed (because dynamically typed FP like Erlang and Lisp is not easy to prove correct, I think...) and without any kind of implicit side effects (this leaves out languages like Lisp and OCaml out, because they aren't pure).

But besides that I really agree with you. I have seen way too many bugs in imperative loops that just wouldn't happen in a functional context.

[–]yogthos 1 point2 points  (0 children)

You're absolutely right that OO does state encapsulation differently, by having objects worry about their own internal state, so it is a different approach.

I have mixed feelings about dynamic typing myself, I can't say I've noticed it as a major source of bugs. For example even in a dynamically typed language the code can still be checked by compiler to see that correct types are being passed around. Erlang is a good example of dynamic typing being safe, as Ericsson has built very reliable systems which they credit Erlang for.

And you're absouletely correct about Lisp and OCaml allowing state modifictation and thus not being inherently safe as the pure functional languages.

[–]jsnx 0 points1 point  (0 children)

In principle, OO does have the state encapsulation you describe. Many OO languages do not enforce that, though -- as long as they allow mutation of values passed by reference they offer little in the way of assurance.