I prefer to define a local func that returns the default values. https://play.golang.org/p/UOPdouwoy0v
(Moreover you should avoid using `else` behind `return`) Le lundi 22 juillet 2019 21:08:53 UTC+2, Robert Engels a écrit : > > Depends on the length of the function, and number of branches/tests/nested > levels IMO. > > Having clearly labelled exit points at the end has been a best practice > for a long time AFAIK. This is especially true with multiple return values, > and if different exit points return values that are dependent on > computation prior. It also the return values to be more easily > self-documented IMO. > > -----Original Message----- > From: Tong Sun > Sent: Jul 22, 2019 2:01 PM > To: golang-nuts > Subject: Re: [go-nuts] Preparing defaults for multiple-values-returning > functions > > > > On Monday, July 22, 2019 at 2:59:33 PM UTC-4, Burak Serdar wrote: >> >> On Mon, Jul 22, 2019 at 12:51 PM Tong Sun <sunto...@gmail.com> 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 >> >> https://play.golang.org/p/_U4CvzTBxkX >> > > > Ah, bingo! This is much better than the "goto return_defaults" solution > in my view. THX a lot! > > > >> >> > >> > thx >> > >> > -- >> > 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 golan...@googlegroups.com. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/b74868fc-65a0-4b04-a898-411139b3b9f8%40googlegroups.com. >> >> >> > -- > 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 golan...@googlegroups.com <javascript:>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/461b3039-182d-4796-9491-3da131871363%40googlegroups.com > > <https://groups.google.com/d/msgid/golang-nuts/461b3039-182d-4796-9491-3da131871363%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > > > > -- 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/78a37d20-d163-4140-949c-fe67842363ba%40googlegroups.com.