Talk:Closure (computer programming): Difference between revisions

Content deleted Content added
Ruud Koot (talk | contribs)
Line 738:
::: The main difficulty that most people have when trying to understand closures is that a lot of popular languages like C, Java and C# 1.0 don't have nested functions and therefore no non-local variables (only local and global variables). So in those languages you generally don't need a closure, a function pointer is sufficient.
::: You can find a lot of discussion on the Internet on whether closures and objects are equivalent. While you can see closures as a simple kind of objects, I don't think that view is really helpful in understanding what closures are. You can do things with objects that you can't easily do with closures (have more than one member function, have public member variables, polymorphism, etc.) and things with closures that you can't easily do with objects (two closures can share the same "private member variable" and use it as a private communication channel, which objects can't directly any language I know.) There is a lot of literature on building object systems on top of closures and simulating closures using objects, but that isn't how they are primarily used in languages that support those features. —''[[User:Ruud Koot|Ruud]]'' 16:43, 21 September 2011 (UTC)
:::: Very helpful, thank you! I think I see the dilemma now, between clarity and precision. My only recommendation is to avoid giving the reader another definition in the second sentence. Instead, allow the reader to take a breath. You may want to begin the second sentence with, "In other words..." or "In a sense, this means..." and follow with very simple language to catch anyone who was left behind.
''In computer science, a closure (also lexical closure, function closure or function value) is a function together with a referencing environment for the non-local variables of that function. A closure allows a function to access some variables outside its typical scope.''