Hacker News new | past | comments | ask | show | jobs | submit login

Go:

  func f() error {
    var a, b, c *handle
    var err error	
    if a, err = acquireHandle(0); err != nil {
  	return err
    }
    defer a.Close()
    if a, err = acquireHandle(1); err != nil {
  	return err
    }
    defer b.Close()
    if a, err = acquireHandle(2); err != nil {
  	return err
    }
    defer c.Close()
    //use a, b, c
    return nil		
  }



Thanks for the example, seems like Go's solution is better than C but has the same problems as C#: non composable and leaky.


It's significantly worse actually, as the acquire call does not imply the dispose. Disposal has to be invoked separately, even if close to acquire.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: