Closing over Variables
Jump to navigationJump to search
Revision as of 11:34, 20 July 2011 by Jrose (New page: == Closing over variables considered harmful http://blogs.msdn.com/b/ericlippert/archive/2009/11/12/closing-over-the-loop-variable-considered-harmful.aspx Agreeing with the author: John...)
== Closing over variables considered harmful
Agreeing with the author:
John Rose 22 Jan 2010 8:56 PM @Konrad: "I much prefer Java’s rule here: only allow closing over variables which are declared `final`. But then, this only works because Java allows local variables to be declared `final`, which C# doesn’t." The reason Java supports final variables is exactly to fix this problem. The designer of inner classes was a Lisp refugee who had been bitten by the DOTIMES issue (see Peter Seibel above), and didn't want to allow the problem into Java. This particular barn door is hard to close after the mutable iteration variable has galloped away.
== Closing over variables considered beneficial
From your internal interator body, you can manage loop accumulators as if by a primitive while loop.