this post was submitted on 20 Mar 2024
18 points (87.5% liked)

Golang

2197 readers
1 users here now

This is a community dedicated to the go programming language.

Useful Links:

Rules:

founded 1 year ago
MODERATORS
top 13 comments
sorted by: hot top controversial new old
[–] wyrmroot@programming.dev 9 points 7 months ago (2 children)

I hate seeing data encoded into magic comments, struct tags included. One of my biggest gripes with Go is that I think they should have used a different symbol to distinguish important annotations from true comments.

[–] firelizzard@programming.dev 3 points 7 months ago

Who uses struct tags for comments? I’ve never used or seen them used as anything except annotations as in tag:"value". And linters (go vet?) will tell you if you’re formatting them wrong.

[–] YIj54yALOJxEsY20eU@lemm.ee 1 points 7 months ago

I used the embed feature to embedd some files into the binary recently. It feels so hacked together.

[–] Ephera@lemmy.ml 5 points 7 months ago (1 children)

So, I don't code in Go and have no intention to. But my impression was that Go is intentionally simplistic. Now I read about this iota keyword, which seems like such a niche thing to include into the language, like what the heck. Is there any other use for it, aside from creating pseudo-enums?

[–] sxan@midwest.social 2 points 7 months ago (1 children)

Nope. Of all the silly things to include in an intentionally pared-down language, iota is maybe the dumbest thing in the language. I think the purpose was to provide a default value, because one of the things that was talked up when the language was young was how every variable had a default value - there were no undefined values for any types. But honestly, I don't know; it seems a waste.

And I say this as someone who still hasn't personally found a better language than Go, except maybe C99. The language has warts, but at least - unlike a commonly compared and currently popular language - it doesn't look like it fell out of the ugly tree and hit every branch on the way down. And I believe Go's remaining warts will be resolved, eventually.

[–] Ephera@lemmy.ml 3 points 7 months ago

Well, if you're talking about Rust there, then seeing Go's pseudo-enums had me even more confused, why anyone's comparing the two.
Rust not only has enums, they're used everywhere and when combined with pattern matching, they're one of the most powerful concepts in the language...

[–] tux0r@feddit.de 3 points 7 months ago (2 children)

That blog is hard to read on a desktop computer in my opinion. But hey, "it looks cool", at least...

[–] bugsmith@programming.dev 4 points 7 months ago

I agree. The content is reasonably sound, but from a design and UX perspective, it's awful.

[–] pkill@programming.dev 2 points 7 months ago* (last edited 7 months ago)

Firefox and gnome web reading modes ftw

[–] Solemarc@lemmy.world 2 points 7 months ago (1 children)

As far as I was aware Go didn't have enums and this

const()

Pattern is just a weird thing people do because it behaves like an enum?

[–] firelizzard@programming.dev 4 points 7 months ago

You are correct, Go doesn’t have enums. The const thing is a widely accepted pattern for approximating enums.

[–] bugsmith@programming.dev 2 points 7 months ago

A follow up post by the author, original shared and discussed here.

[–] Pixel@lemmy.sdf.org 1 points 7 months ago

Don't understand why people hate them so much. They work fine for me, the go team, and many others. If you want an enum scope you can use the sub package trick. Not ideal but I don't even need that. Iota is cool because it basically repeats any pattern, including bit flags. My biggest beef with them is the ability to assign any literal value to these custom types, but I can handle it. Plus you can wrap in a struct if you care that much. It's just not a big deal.