Closed serras closed 1 year ago
I appreciate the improvements you've made, and it seems like you've addressed the issue with the example. However, now there is a lack of demonstration or illustration of the actual
.memoized()
function, which is designed to work seamlessly with any non-recursive method.
I was actually debating what to do here. On the one hand, memoized
works on every function; but if that function is recursive the recursive calls are not handled correctly. And if you're writing the recursive function by hand, you're better off using DeepRecursiveFunction
than creating a double-recursive function in which the worker calls the memoized function and vice versa.
I appreciate the improvements you've made, and it seems like you've addressed the issue with the example. However, now there is a lack of demonstration or illustration of the actual
.memoized()
function, which is designed to work seamlessly with any non-recursive method.I was actually debating what to do here. On the one hand,
memoized
works on every function; but if that function is recursive the recursive calls are not handled correctly. And if you're writing the recursive function by hand, you're better off usingDeepRecursiveFunction
than creating a double-recursive function in which the worker calls the memoized function and vice versa.
In my opinion, there are really two cases:
.memoize()
. Some functions may take time to compute without making recursive calls, and in such cases, memoize is a good idea. However, I must admit that I don't have a specific example that comes to mind right now.I believe that in the documentation, both the simple .memoized()
approach for a function and the usage of MemoizedDeepRecursiveFunction should be discussed, with a clear explanation of the differences between them. For someone who is new to the documentation, it is not obvious at all, so providing explanations and even illustrating with examples would be beneficial
-- EDIT: That being said, since the focus of this documentation page is on recursive functions, it might be more appropriate to discuss memoization of non-recursive functions in a separate section or dedicate a separate documentation page to it.
@AcartN your explanation makes a lot of sense. I've just pushed a new commit with adds a new separate Memoization section. I've decided to still have "recursive + memoized" live in the Recursion section, because I feel it makes sense to tell the story in that way. In Memoization the discussion is about what are the limitations of memoize
w.r.t. recursion, and then suggests MemoizedDeepRecursiveFunction
as the preferred option if you control the function.
This documentation PR is blocked until we released 1.2.0
.
Fixes #213