Why we need scope(success) if I can write at the end?

2011-01-21 Thread tamir
or what's the differents between theese two: void transactionalCreate(string filename) { string tempFilename = filename - ".fragment"; scope(success) { std.file.rename(tempFilename, filename); } auto f = File(tempFilename, "w"); } and: void transactionalCreate(string filename) { strin

Re: Why we need scope(success) if I can write at the end?

2011-01-21 Thread spir
On 01/21/2011 02:18 PM, tamir wrote: or what's the differents between theese two: void transactionalCreate(string filename) { string tempFilename = filename - ".fragment"; scope(success) { std.file.rename(tempFilename, filename); } auto f = File(tempFilename, "w"); } and: void tr

Re: Why we need scope(success) if I can write at the end?

2011-01-21 Thread Steven Schveighoffer
On Fri, 21 Jan 2011 08:18:15 -0500, tamir wrote: or what's the differents between theese two: void transactionalCreate(string filename) { string tempFilename = filename - ".fragment"; scope(success) { std.file.rename(tempFilename, filename); } auto f = File(tempFilename, "w"); } and

Re: Why we need scope(success) if I can write at the end?

2011-01-21 Thread Jonathan M Davis
On Friday, January 21, 2011 05:18:15 tamir wrote: > or what's the differents between theese two: > void transactionalCreate(string filename) { > string tempFilename = filename - ".fragment"; > scope(success) { > std.file.rename(tempFilename, filename); > } > auto f = File(tempFilename,

Re: Why we need scope(success) if I can write at the end?

2011-01-21 Thread Andrej Mitrovic
When there are multiple calls that can fail, and where I have to do clean-up code in a certain order and under certain conditions I use scope(exit). For example: import std.stdio; import std.exception; void main() { foo(); } enum NoError = true; bool Initialize() { return true; } bool Start

Re: Why we need scope(success) if I can write at the end?

2011-01-21 Thread Jonathan M Davis
On Friday, January 21, 2011 14:49:44 Andrej Mitrovic wrote: > When there are multiple calls that can fail, and where I have to do > clean-up code in a certain order and under certain conditions I use > scope(exit). For example: > > import std.stdio; > import std.exception; > > void main() > { >

Re: Why we need scope(success) if I can write at the end?

2011-01-21 Thread spir
On 01/21/2011 09:56 PM, Jonathan M Davis wrote: On Friday, January 21, 2011 05:18:15 tamir wrote: or what's the differents between theese two: void transactionalCreate(string filename) { string tempFilename = filename - ".fragment"; scope(success) { std.file.rename(tempFilename, filen