The tag has no wiki summary.

learn more… | top users | synonyms

4
votes
3answers
673 views

Is a lambda expression something more than an anonymous inner class with a single method?

There is a new hype with the long awaited lambda expressions in Java 8; every 3 day another article appears with them about how cool they are. As far as I have understood they a lambda expression is ...
10
votes
4answers
945 views

Is garbage collection needed for implementing safe closures?

I recently attended an online course on programming languages in which, among other concepts, closures were presented. I write down two examples inspired by this course to give some context before ...
2
votes
1answer
287 views

What is a closure and how is it implemented in Ruby?

In the context of the Ruby programming language, what is a closure and when do you use one? What are the uses for it in Rails?
6
votes
3answers
322 views

Are closures with side-effects considered “functional style”?

Many modern programming languages support some concept of closure, i.e. of a piece of code (a block or a function) that Can be treated as a value, and therefore stored in a variable, passed around ...
2
votes
1answer
385 views

Using captured non-local variables in C++ closures

On this wikipedia page I have found the following sentence regarding closures in C++11: C++11 closures can capture non-local variables by copy or by reference, but without extending their ...
2
votes
1answer
171 views

Can methods in an OOP language be considered as some kind of closure?

Consider a method m of a class A in an object-oriented language like Java or C++. In the body of the method m it is possible to reference the member variables of the object on which the method is ...
3
votes
1answer
170 views

What is the proper jargon to refer to a variable wrapped inside a function closure?

In JavaScript, there is no such thing as a "private" variable. In order to achieve encapsulation and information hiding in JavaScript, I can wrap a variable inside a function closure, like so: var ...
3
votes
2answers
160 views

Why to keep wrapping closure in each js-file if it can be added after concatenating?

At the moment every javasrcipt file in our project includes closure wrapper. Before deploying all files are concatenated and minimized. And i'm asking myself, do we really need all that closures OR ...
7
votes
2answers
216 views

When we talk about 'a closure' do we refer to a single variable, or do we refer to all 'closed' variables?

Let's take the following (JavaScript) code that returns a function that closes over variables x and y to illustrate: function test() { var x = Math.random(); var y = Math.random(); var f = ...
2
votes
2answers
133 views

Trimming script size by using array notation for frequently accessed properties

I noticed some redundancy in a script I ran through Google Closure Compiler. (function(){function g(a){var k;if(a){if(a.call)a.prototype=j,a.prototype[e]={}}else a= {};var ...
7
votes
3answers
691 views

What common programming problems are best solved by using prototypes and closures?

As much as I understand both concepts, I can't see how can I take advantage of JavaScript's closures and prototypes aside from using them for creating instantiable and/or encapsulated class-like ...
16
votes
1answer
352 views

Does Groovy follow Tennent's Correspondence Principle?

Here's an interesting discussion of Tennent's Correspondence Principle, and a brief description from Neal Gafter: The principle dictates that an expression or statement, when wrapped in a closure ...
27
votes
3answers
986 views

What are the benefits and disadvantages in the approaches of C#, Java and Scala to Closures/Lambdas/…?

I wonder what the technical implementation differences between C# and Scala are and how both solutions compare to the implementation ideas and concerns voiced in the email Peek Past lambda by Brian ...
2
votes
3answers
540 views

difference between passing a value vs passing a function as a parameter in scala

I often hear that scala has a ability to pass function as a parameter to another function. I would like to know the difference between passing a value as a parameter vs passing function itself as the ...
9
votes
3answers
685 views

Why is there so much buzz about closures? [closed]

Why is there so much buzz about closures among developers? In my career I never intentionally used them, though don't clearly understand what they are. UPD: just to clarify. The question is about why ...
12
votes
6answers
1k views

Why is closure important for JavaScript?

C#'s lambda expression also has closures but is rarely discussed by the C# communities or books. I see far more JavaScript people and books talk about its closures than they do in the C# world. Why is ...
2
votes
3answers
286 views

How to avoid shooting yourself in the foot when using closure in JavaScript

The closure feature is widely used in JavaScript and make it quite difficult for programmer who was used to program in a no-closure language. So what is the best practice about using closure and how ...
11
votes
4answers
537 views

How will closures in Java impact the Java Community?

It is one of the most talked about features planned for Java: Closures. Many of us have been longing for them. Some of us (including I) have grown a bit impatient and have turned to scripting ...
3
votes
1answer
493 views

what are the benefits of closure, primarily for PHP?

I am beginning the process of moving code over to PHP 5.3 and one of the most highly touted features of PHP 5.3 is the ability to use closures. My understanding of closures is that they allow ...
38
votes
9answers
7k views

What is a closure?

Every now and then I see "closures" being mentioned, and I tried looking it up but Wiki doesn't give an explanation that I understand. Could someone help me out here?