It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

3

How would you be able to intentionally use something which you don't know what it is? So basically you should first be asking (or searching rather) what closures are.
–
Steven JeurisJul 6 '11 at 14:15

1

Did you read the wikipedia article? What did you fail to understand about it?
–
kevin clineJul 6 '11 at 14:18

2

What is your career based on?
–
user1249Jul 6 '11 at 14:20

4

What kind of a question is this? What "buzz"? What don't you understand? Why didn't you ask that question instead?
–
AaronaughtJul 6 '11 at 14:24

4

In defense of the OP, closures are an old concept but only recently have they been the talk of the town, so to speak. And the concept is indeed very simple to anyone who's learned a bit more maths, I also can't understand why people talk about them as if they were something very difficult to comprehend. Maybe that's just a way to make themselves look smarter: "look, I grok closures which are so hard to grok, so I rock".
–
quant_devJul 6 '11 at 16:42

3 Answers
3

A closure is code that remembers the world where it came from while still being usable where it has been brought to.

An example is defining an anonymous function in Java which knows that it is inside YourObject and can manipulate its methods and functions. This function is then delivered to e.g. Swing where it goes deep inside e.g. a Listener but still has a lifeline back to its roots.

This is a very powerful concept as it allows you to deliver code which - unbeknownst to the code using it - can reach back into other parts of the code.

Yes. It's a way to inject not only procedure, but state, into other code. This allows for a very high degree of flexibility in designing algorithms; you can design templated methods which depend on stateful subroutines, which it may not even know about at compile-time. The downside is that the link to that method's original source, and thus state, can be broken without the consuming method knowing about it; when that happens you get hard-to-find runtime errors.
–
KeithSJul 6 '11 at 16:45

Closures are just something to solve a variety of problems in an elegant way. Actually, in programming languages where no closures exist, techniques are created to implement similar functions.

Just think of functors in C++ or Runnables in Java. They are just techniques that allow functionalities similar to closures. Some kind of « manual closures ».

Closures are getting more popular because they are integrated into popular languages : Javascript is growing due to online applications (like google doc for example), C# implemented it, PHP implemented it since 5.3, and so on.

Now that closures are available in more and more technologies, it becomes quite straightforward that more and more people are interested in them.

So now, what are closures ? This is quite simple. A closure is a function and a context to execute it within. This is manipulated as an object. Why is this useful ? This is useful to hook your own code into existing code.

Here are two common situations which require that : when actions are managed by another piece of code, like in multithreading with a thread pool, or when an action has to be executed on a choosen event (used often in javascript for the UI).

Did I clearly understand you? There are some "manual closures" (not really a closures, but something that resembles their behavior) and there some "TRUE closures"?
–
user1449Jul 6 '11 at 14:35

Closure is a language capability. Some language doesn't have that capability, so you have do closure manually using tools that the language provides to you. Saying that they are TRUE or not isn't a very interesting debate IMHO.
–
deadalnixJul 6 '11 at 14:41

2

@gasan, you can always whip out the assembly and manually perform whatever pattern you want with a bucketful of GOTO statements. Similarly you can manually perform a "for" loop with a "while" loop (in C++). The more advanced, higher levels offer a standardized way of doing common things.
–
PhilipJul 6 '11 at 15:05