News for hackers. Stuff that matters.
Re:Twelve Go Best Practices by xfax on Thursday August 01, 2013 @08:54AM (#6139880)
I agree, having a single return point makes debugging that much easier.

Back at Microsoft, the following pattern was used quite extensively in the OS group:

  int someFunc() {

    DWORD error = ERROR_SUCCESS; 

    error = foo();
    if (error != ERROR_SUCCESS) {
      goto Clean0;
    }

    error = bar();
    if (error != ERROR_SUCCESS) {
      goto Clean0;
    }
    
      ....

    Clean0:
    return error;
  }
Re:Twelve Go Best Practices by philsnow on Thursday August 01, 2013 @02:39PM (#6142427)
This style is used in the linux kernel as well; there can be multiple resources acquired that sometimes need to be released in reverse order, so there are often multiple labels that you can goto, depending on how much stuff you have to unwind before you return.