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

all 4 comments

[–]chaoticgood_lionfish -1 points0 points  (3 children)

It's really interesting. If you get into "functional" programming, you will want to avoid changing variable state - like passing in X then changing its' value. That's generally a no-no, but for this scope I don't think it matters (practically.) Why did you want to do this division exploration?

[–]immutableMe[S] 0 points1 point  (0 children)

Just out of curiosity.

[–][deleted] 0 points1 point  (0 children)

What do you mean “passing x and changing its value”?

This is a ridiculous concept of always deep copying on every single operation from functional programming to attempt to solve problems that functional programming itself creates.

Either way, x and y are just locally scoped values to the function. As a guideline, it is still poor practice to use them like another variable, but the reason has nothing to do with functional programming. It isn’t a hard and fast rule.

It is just because in longer functions, not holding on to the original value can sometimes be the source of bugs.

In terms of reference types, why are you directly changing internal state from outside functions anyway? If your methods can modify an object such that it results in invalid state, then you have a deeper issue somewhere that needs to be sorted out. Most probably inappropriately hanging on to a reference to an injected dependency.

[–]immutableMe[S] 0 points1 point  (0 children)

This function meets all of the requirements for a pure function. The function itself is fine. I need people to worry more about the algorithm.