Oh, I got that – I just got sidetracked with the general language design issue. I think we're better off just sticking with open as it is. Either way it will be unfamiliar to some people – at least using open like this will be familiar to people coming from Ruby (not an insubstantial segment of programmers). Calling it withfile is a bit weird because the main thing that the function call does is open the file for you. It's just that it also closes it for you too and the binding is scoped to just the region where the file is open.
On Mon, Apr 28, 2014 at 12:36 PM, Simon Byrne <[email protected]> wrote: > On Monday, 28 April 2014 17:20:34 UTC+1, Stefan Karpinski wrote: >> >> Python has the with >> keyword<https://docs.python.org/release/2.5/whatsnew/pep-343.html>, >> which serves a similar role. However, I have to admit that I've never >> really understood how the Python style `with` approach is a better than the >> Ruby-style (do)-blocks. The with keyword seems more limiting since you >> can't, for example, evaluate the block multiple times. Does anyone have any >> reasons why the with approach is better? >> > > Sorry, I should clarify, I didn't mean to rename `do`, I meant renaming > `open` in the case where a function is the first argument. e.g. > > withfile("outfile", "w") do f > write(f, data) > end >
