this post was submitted on 25 Sep 2023
4 points (62.5% liked)

Golang

2434 readers
9 users here now

This is a community dedicated to the go programming language.

Useful Links:

Rules:

founded 2 years ago
MODERATORS
 

Did I break a taboo by doing this?

you are viewing a single comment's thread
view the rest of the comments
[–] theherk@lemmy.world 3 points 2 years ago (1 children)

I don’t think it is a taboo, but it is possibly just worse code in many cases. Handling error values is usually something that should be done thoughtfully. Panic is nice but can easily be overused and should not make it out of a package.

I too wish there was a better way, but in the form of proper enums and result and option types. However, wrapping in functions is fine in some cases not taboo.

As an aside, you probably don’t need a static union type for your min and max functions. I assume you could use comparable.

[–] danhab99@programming.dev 2 points 2 years ago (1 children)

As an aside, you probably don’t need a static union type for your min and max functions. I assume you could use comparable.

comparible only allows ==

[–] theherk@lemmy.world 2 points 2 years ago (1 children)

Oh right! What am I saying? contraints.Ordered maybe.

[–] danhab99@programming.dev 1 points 2 years ago

I just looked at the standard docs and I didn't realize there was a built-in min and max function. Y'all should really read the standard lib docs.. it's fascinating in there.