HNHacker News
TopNewBestAskShowJobs

casualsuperman2

7 karma · joined February 7, 2012

submissionscomments
casualsuperman2··on Go is amazing, period.
The current weekly release has (and Go v1 will have) runtime.NumCPU() so you can do runtime.GOMAXPROCS(runtime.NumCPU())
casualsuperman2··on The Go Programming Language, or: Why all C-like languages except one suck.
And then in the code for handling the error, you can do

   switch err.(type) {
      case db.IOError:
          // Database exception here
      case io.FileNotFoundError:
          // File exception
      default:
          // Pass it to our caller for them to handle.
          return nil, err
   }
Which gives you the ability to selectively catch errors based on type.
casualsuperman2··on The Go Programming Language, or: Why all C-like languages except one suck.
In Go, the accepted way to report errors is to take advantage of multiple returns, such as:

   result, err := somePotentiallyFailingFunction()
   if err != nil {
      // Try to recover here
      ...
      // Not recoverable?
      panic()
   }
And this call to panic works the way you prefer. Note that doing the following:

   result := somePotentiallyFailingFunction()
won't compile since the number of values on the left doesn't match the right, so if a function can fail and returns an error, you will know. If you do something like:

   result, err := somePotentiallyFailingFunction()
And then never check err, it's actually a compile-time error, which enforces error checking, to a point. What's next is the kind of thing you don't like, and it's poor style.

   result, _ := somePotentiallyFailingFunction()
This assigns the error to _, which causes no errors if you don't use it.

Hope this clears some things up.

casualsuperman2··on Poll: When did you start programming in your free time?
12. I was coding JavaScript for ProBoards. I shudder just thinking about it.