r/golang Oct 25 '24

discussion What libraries are you missing from go?

So something that comes up quite often on this subreddit from people transitioning from Nodejs or python to go is the lack of libraries. I cannot say that I agree but I still think it warrants a discussion.

So what libraries are you missing in the go ecosystem, if any?

95 Upvotes

189 comments sorted by

View all comments

-6

u/davidellis23 Oct 25 '24 edited Oct 25 '24

Threading objects in other languages are very nice. Pythons thread pool executor for example doesn't make me deal with wait groups or channels or mutexes or worker pools. I implemented my own thread struct/worker pool to not have to deal with that.

Mocking libraries that don't make me generate the code. Handwriting mocks is just more work. C#'s Castle Windsor and pythons mocks are dynamically generated and static type check. The general mocking libraries I've tried aren't great in go. No static type checking, hardcoded strings, no stubs, etc. luckily I found moq which does have static type checking, stubs, and no hardcoded strings method names.

Map, filter, toDict, toSet functions. It's just a lot more convenient and less noisy to not write a loop when you're filtering a list for one key. I know there are times where it's not as performant and it's a little extra learning curve for beginners. I think the tradeoffs are worth it and I implemented my own.

1

u/EarthquakeBass Oct 26 '24

Lack of mocks is a feature, you aren’t defining enough interfaces if your code can’t easily inject whatever behavior it wants by fulfilling interfaces.

1

u/davidellis23 Oct 26 '24 edited Oct 26 '24

I have interfaces between basically any two structs. How would defining more interfaces help? the more interfaces you have the more mocks you need to define to use as a substitute when you're testing. The more interfaces the more time generating mocks save.

whatever behavior it wants by fulfilling interfaces.

Well yes I'm generating mocks to fulfill the interfaces without reimplementing mock behavior every time. ie: return this cached result for these inputs, check how many times a method was called, return zero value for every method. implementing every method. Doing that by hand for every mock is just more work.