2 ms·
I realized I don’t understand idea of pure functions anymore. If a function fetches a web page it is not pure because it modifies some state. But if function mo
by kikimora 2y ago
I realized I don’t understand idea of pure functions anymore. If a function fetches a web page it is not pure because it modifies some state. But if function modified EAX register it is still pure. How creating a socket or changing a buffer is different from changing a register value considering that in all cases outside observers would never know?
- tines 2y agoPurity is relative to a given level of abstraction?
- entropicdrifter 2y agoIf a function is pure, it can take in and output 100% unmodifiable values. There will never be any side-effects in a pure function. In other words, if you need to modify the contents of a variable for a function to run, that's not a pure function. Taking something in and outputting something just like it but with some modifications is allowed, so long as the input is unmodified. Does that make more sense? You can't modify anything inside a function that originated from outside of the function's scope.
- betenoire 2y agoI think they understand that, and are referring to more nuanced side effects. Logging, for an example, is a side effect, same with even using a date function. Hitting an API endpoint without cache may be functional if the response never changes, but do you want that? Usually we want a cache, which is skirting idempotency. The closer you look, the more side effects you see
- williamdclt 2y agoLet’s put your uncertainty to rest: at the extreme, any function execution spends both time and energy, both of which are observable side-effects. So yes, you’re right that there no such thing as an absolutely pure function. “Pure” always assumes that all dependencies are pure themselves. Where it’s a reasonable assumption and whether it’s still useful or not depends on your program: assuming an API call to be pure is certainly not reasonable for many use cases, but it is reasonable enough to be useful for others.
- jerf 2y agoIt so happens that this was the topic of one of the posts in this series: https://jerf.org/iri/post/2025/fp_lessons_purity/#purity-is-relative https://jerf.org/iri/post/2025/fp_lessons_purity/#purity-is-... I'm assuming from your post you haven't come from there, and we just coincidentally picked a similar example...
- your_fin 2y agoThe author addresses this nicely in an earlier part of the blog book: https://jerf.org/iri/post/2025/fp_lessons_purity/ https://jerf.org/iri/post/2025/fp_lessons_purity/