Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^3: use Memoize;

by sundialsvc4 (Abbot)
on Jul 18, 2018 at 20:45 UTC ( #1218785=note: print w/replies, xml ) Need Help??

in reply to Re^2: use Memoize;
in thread use Memoize;

I don’t think that we need to review how Memoize necessarily must do what it does.   It is, indeed, perfectly obvious that it must consider the entire parameter-list to form its cache-key in order to return the correct result.   Therefore, it is nonsensical to suggest that I somehow didn’t grok that.

My concern is very specific – that Memoize is a too-clever-by-half approach that might well break(!) a program, and do so in a way that you do not initially detect.   There are precious few “pure functions” in the real-world of computer programming, so you might very easily use this tool, rejoice that “now it runs so much faster!,” and simply not realize that you have not only fundamentally changed the behavior of the program, but have done so in a way that is dependent upon the input data!   Most importantly, the source-code no longer accurately reflects what the program will do:   its behavior is now literally dependent upon the sequence in which parameter-lists have been presented to this function.   It is difficult if not impossible to test this.

Knowing, therefore, that in the real world functions are usually not “pure,” I would instead resort to “more pedantic” logic that is objectively testable.

... and I will be the very first to state that this is my opinion, and nothing more.

However, this opinion is borne from the experience of constantly working with very-big, very-old legacy systems that cannot be understood in their entirety by anyone who is working on them now.   Viewed from this perspective, anything “far away from here and therefore very-easily overlooked,” which might cause the behavior of the system to deviate from “what the source code says,” is pretty-much a disaster.   To the point that, yes, one of my “initial assessment tasks” is to look for Memoize, re-engineer all of the cases that might be found, and create tests.

That’s my point-of-view on this, and it is legitimate.

Replies are listed 'Best First'.
Re^4: use Memoize;
by chromatic (Archbishop) on Jul 19, 2018 at 00:05 UTC

    You don't trust programmers to know if they've written pure functions, but you trust programmers to write logic that always gets cache key management right. Okay.

    You don't believe it's possible to test caching the result of pure functions, but you rigorously write test cases for manual caching operations.

    I'm starting to get the idea you don't trust functions or don't understand the isomorphisms of abstractions like functions.

Re^4: use Memoize;
by Anonymous Monk on Jul 18, 2018 at 23:08 UTC

      Our worst user, much of the repeated nonsense boils down to a 'do as I say, not as I do' responses. As you correctly point out here this user is a terrible hypocrite.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1218785]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2019-12-08 15:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found