Feedback and comments on ARM proposal (original) (raw)
Neal Gafter neal at gafter.com
Thu Mar 19 12:17:33 PDT 2009
- Previous message: Feedback and comments on ARM proposal - resend
- Next message: Feedback and comments on ARM proposal - resend
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Mar 18, 2009 at 5:18 PM, Howard Lovatt <howard.lovatt at iee.org> wrote:
For example suppose as Neal has suggested that the foreach loop understood resources, it would be great to write something like:
for ( final String line : AutoResources.asLines( filename ) ) { ... }
Howard-
I think you may have missed my point. It isn't the Iterable that the for-each loop needs to handle as a resource, because the programmer can easily do that himself
try (final AutoResource linesInFile = AutoResources.asLines(filename)) { for ( String line : linesInFile ) { ... } }
Rather, I'm talking about the implicit Iterator variable that is created by the expansion of the for-each loop. Unlike Iterable, Iterators are one-shot, so making one a resource is natural. But, with the current ARM proposal, there is no way to use the for-each loop with an Iterable whose Iterator is an AutoResource. Experience with C#'s foreach loop and IDisposable/IEnumerable has shown the combination to be very useful, as it avoids some very awkward situations when both resources and loops are used together in a program.
These kinds of issues make me think that more actual experience with the proposed construct will be required before we can have confidence that it is "right".
Regards, Neal
- Previous message: Feedback and comments on ARM proposal - resend
- Next message: Feedback and comments on ARM proposal - resend
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]