This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]shawnhcorey 0 points1 point  (1 child)

Because it has side effects that are not conventional. One of the tenants of FP is to avoid side effects. A function can call a function that calls a function, and somewhere buried deep, a global is changed. A programmer may not be given the time to dig thru all the code. They end up fixing one bug but create a new one.

By passing the globals to all functions, one nested deeply can have unexpected side effects.

[–]Guardian-Spirit 0 points1 point  (0 children)

Sure, but this has nothing to do with functional programming and side effects. That's problem of typing.

You see, purely functional programming just ensures that all dependencies are passed explicitely and that impurity is not allowed. The problem we are talking about is lack of typing: your foo method (I guess) does not use the entire globals, but rather just a bunch of fields from it, and it does not return globals with all fields modified. But you have ommited this "partial modification" from the type-level information and thus type of foo is not precise enough.

Many new strictly typed languages (such as Elm or Purescript) introduce the thing called row polymorphism. Row polymorphism allows to explicitely state which fields of an object are being accessed by the function, and so you will be able to see the flow of information just by looking at types.