Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>> An array append function which returns a new array with the new element appended is purely functional.

>> The same function applied to the same input will always return the same value, and won't cause that to break for any other functions.

I think this is the essence of why a lot of developers use functional programming but I think that in this case functional programming is not a solution to the real problem which is an architectural problem.

If the relationship between different components in your system is clear and hierarchichal, you should never need to keep the same data/array in two places. You can come up with simple abstractions so that you only ever have one source of truth for each kind of state. That means you can read it anywhere but only write to it in one place.

I think that functional programming cannot solve this root problem, you will just end up with different symptoms. For example, instead of mutating a single array in unexpected ways, in FP, if you have multiple sources of truth, you might end up with multiple conflicting copies of the same data. Same root problem and it's just as difficult to identify and debug as in OOP, just different symptom.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: