On Monday, July 22, 2019 at 2:51:43 PM UTC-4, Tong Sun wrote: > > I want to define a default set of values for the multiple-values-returning > function, so when doing error checking along the way, I can return such > default set when things go wrong. > > How can I do that? > Is it possible to make the 17&18 line of the following working? > https://play.golang.org/p/OX6QwWXc2ch > > thx > > My 2 cents. I'm a seasoned Go programmer with years of professional Go experience, and decades of coding work.
Personally, I would avoid goto if possible. It may "have been a best practice for a long time" in C/C++ and other languages. But in Go there are usually better ways to write code. The are situations where a goto for exit cleanup is the clearest solution, but I recently worked on a 50k line project where we only did it once. Another, a personal preference - I dislike bare returns in most situations. I know I am not alone in this opinion. Specifying the return values explicitly is just clearer, avoids a class of bugs, and can make reading the code quicker and easier. func ret2(b bool) (int, int) { if b { return 1, 2 } return 2, 3 } Or func ret2(b bool) (x, y int) {x=1 y=2 if b { return } else { x,y = 2, 3 return -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b1b11fcd-5796-49b0-9346-1a222c6a6e32%40googlegroups.com.