out := file.out
try {
// ...
} finally {
out.close
}
// vs.
using (out2 := file.out) {
// ...
}
I think in Fan, maybe it should always call close (determined statically) independent of implementing any particular interface. Sort of like how operator shortcuts work.
brianWed 23 Jul 2008
No, I was waiting to see if anything shook out from using closures using just {}. If that doesn't happen in the next few months, then I'll probably implement C# style using. Or might just add some closure based methods:
file.out.with |OutStream out|
{
}
Not quite as nice though as the using sugar.
jodastephenThu 24 Jul 2008
I think I prefer the closure method style - if your language has closures, why not use them?
tompalmerThu 24 Jul 2008
After learning Ruby, I used to extol the closure style. It works without extra language features. But using has the value of encouraging consistent convention. That is, without using, you might have to think more about how to get your resources closed. Which method to call?
Still, Ruby (or Fan if using the same style) is better than Java where you have to guess the method to use and remember to use try and finally correctly.
I'm not convinced using blocks are the best choice, but I think they have virtues to consider.
And every closure in Fan means normal return isn't available. I guess one school says you shouldn't scatter returns through your code, anyway. I'm not of that school, but it could be an argument that closure constructs in Fan aren't so bad.
Anyway, I'm fine with the "wait and see" plan for now. (Just needs addressed in one fashion or the other before a publicized, stable 1.0 release.)
tompalmer Wed 23 Jul 2008
Does Fan yet support
using
blocks from C#?I think in Fan, maybe it should always call
close
(determined statically) independent of implementing any particular interface. Sort of like how operator shortcuts work.brian Wed 23 Jul 2008
No, I was waiting to see if anything shook out from using closures using just
{}
. If that doesn't happen in the next few months, then I'll probably implement C# style using. Or might just add some closure based methods:Not quite as nice though as the using sugar.
jodastephen Thu 24 Jul 2008
I think I prefer the closure method style - if your language has closures, why not use them?
tompalmer Thu 24 Jul 2008
After learning Ruby, I used to extol the closure style. It works without extra language features. But
using
has the value of encouraging consistent convention. That is, withoutusing
, you might have to think more about how to get your resources closed. Which method to call?Still, Ruby (or Fan if using the same style) is better than Java where you have to guess the method to use and remember to use
try
andfinally
correctly.I'm not convinced
using
blocks are the best choice, but I think they have virtues to consider.And every closure in Fan means normal
return
isn't available. I guess one school says you shouldn't scatter returns through your code, anyway. I'm not of that school, but it could be an argument that closure constructs in Fan aren't so bad.Anyway, I'm fine with the "wait and see" plan for now. (Just needs addressed in one fashion or the other before a publicized, stable 1.0 release.)