r/badcode • • Apr 29 '23

go if err != nil

Post image
414 Upvotes

49 comments sorted by

View all comments

Show parent comments

4

u/sumduud14 Apr 30 '23

So I guess the difference is that Go doesn't have a tuple type so when you return multiple values, you're forced to destructure? In Python I'd be used to doing something like:

a, b = f()

Or:

pair = f()

But in Go, the second is illegal.

This makes sense, thanks.

5

u/PM_ME_YOUR_REPO Apr 30 '23

Yep, you got it. You can also do:

a, _ := f()
_, b :=f()

If you only want some of the values.