--
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...@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.
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
>
> 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.
-----Original Message-----
From: Tong Sun
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/461b3039-182d-4796-9491-3da131871363%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/461b3039-182d-4796-9491-3da131871363%40googlegroups.com.
func ret2(b bool) (int, int) {
if b {
return 1, 2
}
return 2, 3
}
func ret2(b bool) (x, y int) {
x = 1
y = 2
if b {
return x, y
}
return 2, 3
}
On Monday, July 22, 2019 at 2:51:43 PM UTC-4, Tong Sun wrote:
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.Or
func ret2(b bool) (int, int) {
if b {
return 1, 2
}
return 2, 3
}
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...@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.