News for hackers. Stuff that matters.
Re:Tom Duff: Reading Code From Top to Bottom (1999) by chadnickbok on Saturday June 04, 2011 @10:44PM (#2621139)
One, very simple, example:

int some_function( some_variable ) {

  if (some_variable) {
    b = 1;
  } else {
    b = 2;
  }

  log("Its important I log that I'm returning %d\n", b);

  return b;
}

If its not obvious why this is superior...

Re:Tom Duff: Reading Code From Top to Bottom (1999) by enneff on Sunday June 05, 2011 @04:34AM (#2621643)
Go's defer feature, combined with named return values, lets you do this:

    func someFunction(b bool) (i int) {
        defer func() {
            log.Printf("I'm returning %d", i)
        }()
        if b {
            return 1
        }
        return 0
    }
For more on defer, see this blog post: http://blog.golang.org/2010/08/defer-panic-and-recover.html
Re:Tom Duff: Reading Code From Top to Bottom (1999) by cpeterso on Sunday June 05, 2011 @01:21AM (#2621374)
The single return is also useful for post-condition assertions of return values and internal state.
Re:Tom Duff: Reading Code From Top to Bottom (1999) by jtolle on Sunday June 05, 2011 @01:52PM (#2622466)
This of course exemplifies why it's impossible to declare almost any technique categorically "good" or "bad". Sometimes early returns make code shorter and more clear. Sometimes the opposite. To borrow from Stroustrup, experience and taste matter a lot.
Re:Tom Duff: Reading Code From Top to Bottom (1999) by alisey on Sunday June 05, 2011 @12:27AM (#2621299)
In dynamic languages you can do this:

  some_function = function() {
    if (...) return 1;
    if (...) return 2;
  }.log("It's important I log that I'm returning");
Re:Tom Duff: Reading Code From Top to Bottom (1999) by palish on Saturday June 04, 2011 @11:44PM (#2621231)

  int some_function( some_variable ) {

    log("Its important I log that I'm returning %d\n", (some_variable ? 1 : 2));

    return (some_variable ? 1 : 2);
  }
Re:Tom Duff: Reading Code From Top to Bottom (1999) by mrspandex on Sunday June 05, 2011 @12:51AM (#2621335)
Now you're duplicating logic for a log statement...
Re:Tom Duff: Reading Code From Top to Bottom (1999) by mahmud on Sunday June 05, 2011 @03:00AM (#2621539)
I have a new _no_ computation in log statements rule. A bug in there is nigh near impossible to fix because you're not looking for it.