I will have a presentation about closures, and a non programmer friend of mine asked, what closures are. With what analogy would you describe that?
I mean “take a look at the lamba calculus” wouldn’t be that nice.
8
Based on your comment I’m going to assume the target audience doesn’t fully understand what a “function” is either, so here are my best attempts at defining “function” and “closure” to somebody who has not ever written code of any sort.
A function is a piece of code that I can give some data, and it will
give me back a result. For instance, I might have a function to compute
the square root of a number.A closure is one way of making a function that can also “save” data
and “remember” it later. For instance, I might have one closure to
change an image’s size, and another to check what the image’s size
currently is.
1