Hacker News new | ask | show | jobs
by bcgraham 3985 days ago
An idea is to include a function in the library called MustNewServer() that panics instead of returning an error. A usability perk of having single return is that the function can be chained, i. e.,

    ws := gowork.MustNewServer(key).AddParams(...)
3 comments

As much as I hate chaining functions, I do like the idiom of declaring that a function may panic with the 'Must' prefix.

As long as there is an alternative function which returns errors :)

Thanks for the suggestion, i'll add something similar to this when i've got a bit of time. Cheers!
Great suggestion---I recant my original comment and second this.