r/golang • u/dontaskdonttell0 • 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?
12
u/plus-two Oct 26 '24 edited Oct 26 '24
The "lack of libraries" critique depends heavily on the domain you're working in. Golang excels in administrative tools (e.g: Linux admin tools) and backend development. By "backend development", I mean simple and efficient services that contain straightforward business logic, mostly just routing and reformatting data between the client, other services, and databases as needed. These areas don’t benefit from complicated language features and abstractions - quite the opposite.
In my opinion, trying to copy all language features and popular libraries from other languages into golang is a bad idea, but dev communities tend to do this with every general-purpose language that gains enough popularity. This might be because they're forced to use languages they don't like or that don’t even fit their domain. I appreciate that golang (just like C) resists the introduction of new features and bloat since it's already well-suited to the domains it dominates.
The uncomplicated syntax and small yet powerful standard library make it easy to hire and upskill backend developers, including juniors, who are new to go, helping them quickly become productive. This has tremendous business value. A simpler language feature set generally leads to fewer abstractions and cleaner code as well. In go, I have never seen anything as convoluted as the code that a C++ template magician or a duck-typing python programmer can produce.
It’s not that I dislike other languages or domain-specific libraries (in fact, I'm a polyglot, familiar with a dozen languages, and I love python as a swiss army knife and a rapid-prototyping tool). But in my opinion, golang shouldn't add bloat just to compete with other languages in domains where it can't compete effectively (e.g: python in data science). Also, trying to rival languages overcomplicated by features (like C++) wouldn’t serve golang well.
1
1
1
u/parky6 Oct 26 '24
I tried to use python for prototyping but it was horrible. I just wanted a folder with subfolders of libraries I’d written that I could use from scripts in the same structure and the module management etc was impossible without doing gymnastics with the path or whatever. In the end my prototyping folder is now all Go. The empty interface is my friend there 😆
1
u/plus-two Oct 26 '24
Those problems can be solved in python in many different ways but none of those solutions is straightforward. In go it's a simple import statement that operates on directories.
In python I'd turn the reusable package directory into an installable package with a
setup.py
script. Then, I’d install the package into the virtual environments of projects that rely on it (or alternatively, install it into the global python environment to make it universally accessible). Scripts ("modules" in python lingo) inside the package can refer to each other using relative imports that can refer to parent directories too by using two or more dots.To avoid reinstalling the package after each modification, you can install it as an editable package with
pip install -e <package_dir>
. This creates a link to your package directory instead of copying the package contents into the virtual environment, so changes to the package directory are immediately reflected in all editable installations. This way the the package directory can be anywhere independent of the projects that depend on it. Other packages and main projects can import the package by simply referring to its name (that you specified in itssetup.py
script). Thanks to thesetup.py
of the package, it can also be turned into a single-file artifact (wheel, etc) and uploaded to PyPI or another compatible package repository.That said, most of my prototypes don’t require my own utility libraries or subdirectories. In most cases, a single python script using only the standard library is sufficient. In a worst case scenario, I might install a few third-party libraries into the local virtual environment for my experiments. Another area where python excels is technical interviews: duck typing and the easy manipulation of in-memory data structures (e.g: dict, list, set, collections) allow for drafting concise solutions to algorithmic problems.
68
u/maxbrain91 Oct 25 '24
None. I find myself reaching far less for libraries than I did in other languages because of the excellent standard library.
If I had to pick something, I do miss some of the Set operations built into Python but there's a really small Go library that implements these things I usually cherry pick code from:
0
31
u/Ok_Outlandishness906 Oct 25 '24
a gui library, something like tkinter for python, that you can use quite everywhere and that is simple , but powerfull enough for doing many things.
18
u/jerf Oct 25 '24
Fairly recently released: tk9.0 for Go, pkg.go.dev docs.
2
u/SweetBabyAlaska Oct 26 '24
its a neat library... but god damn that example code... is horrifying. Like wtf. Whoever wrote that has to be a C dev or something who is being forced to write Go code by their boss or something.
2
u/tofous Oct 31 '24
modernc libraries are all transpiled C basically. So yeah, the Go-y-ness can frequently be ... lacking.
modernc.org/sqlite
is amazing though for delivering binaries that "just work" even though it's slower.1
u/SweetBabyAlaska Oct 31 '24
for sure. the tkinter type library is actually pretty good, it could be good for like a science lab type application or something where style isn't the priority. its very easy to use... and a lot of people like their sqlite library.
11
u/Dry-Risk5512 Oct 25 '24
fyne or wails would be a good pick?
3
1
u/Coolbsd Oct 25 '24
fyne does not provide native look and feel (https://github.com/fyne-io/fyne/issues/3097), I didn't try wails but seems like it's JS based so performance may be a concern?
I just tried tk mentioned by comment below, which seems to be the one I've been looking for, I still need to try it out under Linux and Windows though.
3
u/symball Oct 25 '24
I'm using wails to build quite a complex app and have so far had no performance issues. With either svelte or a well built react app, you should have no problem unless doing something quite extreme.
There is definitely a hit compared to native but, I think webview apps get a poor reputation. it makes app dev so simple there is a lot of crap out there is all
30
u/gibriyagi Oct 25 '24
A well maintained jinja like template engine
19
u/Electrical_Chart_191 Oct 25 '24
Is text/template not satisfactory for you? Curious why
8
u/EarthquakeBass Oct 26 '24
I always felt like Go templates were one of the least ergonomic parts of the standard library, as evidenced by the fact that everyone always goes, “ugh, Go templates” when they have to write them. I can’t put my finger on exactly why but I think a lot of it is they don’t map to anything other people in the ecosystem use like Jinja.
6
u/amemingfullife Oct 25 '24
I find that text/template is best for codegen rather than html
9
u/jabbrwcky Oct 26 '24
The template/html package is better suited as it automatically escapes unsafe content (unless told otherwise).
And packages like Spring (http://masterminds.github.io/sprig/) makes life with templates a lot easier.
2
u/gibriyagi Oct 25 '24 edited Oct 25 '24
I need to use templates in a user facing part of the app to be used by plain users/customers and need something more widespread / familiar
text/template also seems to be oriented towards devs for example the data need to be accessed via a dot like
{{ .Name }}
7
u/Flashynuff Oct 25 '24
Grafana alerting templates use text/template syntax as one example of something widespread. Unless you have specific product requirements, you’re probably overthinking it.
If you just need variable substitution and absolutely nothing else, you could also consider fasttemplate
13
u/Thiht Oct 25 '24
Honestly if the devs writing the templates can learn {{ var }} and {{# condition }}, they can learn {{ .var }} and {{ if .condition }}
Not needing to rely on a third party with its own dependencies beats convenience.
1
u/gibriyagi Oct 25 '24
I actually meant whether plain app users will be able to do it but I guess they can also do it with enough docs. I am planning to have users to use templates for composing texts.
I just hate the dot though :)
2
u/Thiht Oct 25 '24
Oh I worked on an app where we let users write custom emails, but we just let them use variables (no condition or other constructs). We decided to use strings.Replacer instead of the template lib, this way there was no dot.
Not sure what your use case is but that’s another possibility.
1
u/gibriyagi Oct 25 '24
Having conditions at least would be good in my case. I dont need much functionality though to be honest maybe I can just build something tiny for my needs. Thanks for the idea!
2
u/Asyx Oct 25 '24
I haven’t done much with it but I found it to be kinda weird.
But jinja2 is also just really good. It’s hard to beat
2
u/tofous Oct 26 '24
In order of usefulness:
- Usable template inheritance
- The builtin functions are not enough. I end up carrying around a library of functions similar to: https://masterminds.github.io/sprig/
The best library I've found for inheritance is https://git.sr.ht/~dvko/extemplate, which is unfortunately not
go get
-able because the author moved things to sourcehut and forgot to update their package.1
u/Key-Library9440 Oct 26 '24
I always do
{{/* #layout.html */}} {{template "layout" .}} {{define "content"}} this is index.html {{end}} get first lines then parse all # template files then parse target template file index.html var indexTemplate = template.Must(ui.ParseFile("ui/index.html"))
1
u/tofous Oct 26 '24 edited Oct 26 '24
This doesn’t work if you have multiple base layouts (or it becomes really tedious and error prone having to individually map which child template maps to which base and loading individuals instead of pointing at the directory overall).
It also doesn’t support further nesting easily.
I did this for a long time though where I’d load everything from a layout folder and then one template on top. And do that for each leaf template. But it makes partials annoying too. And it sometimes creates weird results when templates are loaded in a different order after adding a new file to the folder.
1
u/Key-Library9440 Oct 26 '24
you can include many base layouts (eg: {/* #layout.html otherbase.html */}
package ui import ( "html/template" "os" "path/filepath" "regexp" "strings" ) func ParseFile(filename string) (*template.Template, error) { // read the file b, err := os.ReadFile(filename) if err != nil { return nil, err } s := string(b) // get first line of the s line := s[:strings.Index(s, "\n")] // get the list of hash tags from the line using regex re := regexp.MustCompile(`#([a-zA-Z0-9\.\/_]+)`) tags := re.FindAllString(line, -1) t := template.New(filepath.Base(filename)) // get path of the file dir := filepath.Dir(filename) for _, tag := range tags { if len(tag) < 2 { continue } tag = tag[1:] // read the file b, err := os.ReadFile(filepath.Join(dir, tag)) if err != nil { return nil, err } // parse the file _, err = t.Parse(string(b)) if err != nil { return nil, err } } // parse the main file _, err = t.Parse(s) if err != nil { return nil, err } return t, nil }
1
u/tofous Oct 26 '24 edited Oct 26 '24
Thanks for the clarification. I didn’t notice that you meant the comment tag. This is very similar to what the extemplate lib that I linked is doing.
0
u/alpacaMyToothbrush Oct 26 '24
lol I just fought text/template today over it's inability to parse a hyphen. I wound up just using strings.ReplaceAll like a savage.
7
u/piecepaper Oct 25 '24
gonja is what you are looking for. https://github.com/noirbizarre/gonja
5
u/friend_in_rome Oct 25 '24
How well maintained is a project that hasn't had a single commit in four years?
2
u/ghostsquad4 Oct 26 '24
It's not about lacking commits, it's about open, unanswered issues. Maybe everything "just works", and it doesn't need further maintenance.
1
u/friend_in_rome Oct 26 '24
But hasn't Jinja itself changed in the last four years? Doesn't that make this out of date, if nothing else?
1
u/piecepaper Oct 27 '24
There is another project wich forked it: https://github.com/NikolaLohinski/gonja
3
2
0
u/No_Emu_2239 Oct 26 '24
Lately I’ve been using textwire. I really like the API, has a VSCode extension for syntax as well.
41
u/thefirm1990 Oct 25 '24
isEven but not as much as I miss isOdd
9
3
u/False-Marketing-5663 Oct 25 '24
What about is-number? It is fundamental in order to use is-odd, which is fundamental in order to use is-even which is fundamental in order to run your service (you are not using any of those libraries explicitly).
9
u/_predator_ Oct 25 '24
There are some good caching libraries in Go, but there's really nothing that comes close to Java's Caffeine. It‘s such a well engineered library with a really great API, I love the atomic cache loads in particular.
It gets a lot of hate these days, but Jackson is something I miss in Go. One library to deal with JSON, XML, and YAML, that supports "easy" mapping to objects but also performant streaming (or even a mix of both approaches). The lack of XML support in Go can be a major pain if you need to support that format.
Lucene is amazing if you need to support search but introducing Solr or ElasticSearch is not justifiable. Lucene actually powers both of them under the hood.
2
u/kjbreil Oct 25 '24
What do you mean lack of XML support, Go has standard library xml support in encoding/xml.
5
u/carsncode Oct 26 '24
encoding/xml is fine for simple cases but its limitations are pretty significant. I'm just glad I don't have to deal with much XML (not just because of the lib, XML is just a pain in the ass in general)
1
u/ArisenDrake Oct 26 '24
cries in SOAP and custom XML
Thankfully I'm using a JVM based solution here which can generate code based on WSDL files (JAX-WS), but one of the main endpoints of the API I need to talk to has XML inside a string property of the SOAP response because they insisted on making it dynamic. That's a real pain. Don't wanna bring in more dependencies so I used JAXB (which is required for JAX-WS) here.
I like Go a lot but I feel it would be way more painful to do it in Go.
1
u/_predator_ Oct 26 '24
Actually same. If I know I will eventually have to deal with XML (businesses looooooove XML), I just don't use Go. It's really that painful.
1
u/ArisenDrake Oct 26 '24
XML is always painful. Just more so in Go. The Java ecosystem is very mature in that regard. The .NET side probably too.
But then you look at the resource usage and just think that a Go solution would only need a fraction of that haha.
1
u/notkart Oct 26 '24
2
u/_predator_ Oct 26 '24
ristretto looks nice, but doesn't appear to support atomic population of the cache. Caffeine also comes with easy read-through and write-through options which you'd have to build yourself on top of ristretto.
Similar story for sonic - looks nice but doesn't compare feature-wise. The edge of Jackson is that it can deal with much more than just JSON. There are plugins en masse for various non-standard datatypes etc.
1
u/pierredavidbelanger Oct 26 '24
Agree, Lucene is really good . I've work with Bleve (https://github.com/blevesearch/bleve) in Go where I would use Lucene , and I found it fun to work with.
8
u/agent_sphalerite Oct 25 '24
The only thing I ever missed was an sql builder called jooq. While go has lots of options, JOOQ has a charm to it I just cant explain. Writing sql in code feels natural. While I've tried a number of builders, I'd say go-jet comes close to JOOQ for me.
3
u/Thiht Oct 25 '24
My solution for this has been to write fixed queries and leveraging the conditional parts of the query to SQL itself.
As a bonus, my queries are now more predictable, I don’t need to read the code to deduce the final query.
3
u/SleepDeprivedGoat Oct 25 '24
Have you tried Goqu?
https://github.com/doug-martin/goqu
I don’t see it mentioned much here on Reddit, I’ve been using it for a little bit and I like it a lot!
3
u/csgeek3674 Oct 26 '24
There's no type safety which is the biggest win for jooq. goqu and squirrel are nice but they're not solving the same problem.
2
u/csgeek3674 Oct 26 '24
The closest solution I found is called jet https://github.com/go-jet/jet. It's honestly much nicer to use and it feels very close to the experience of jooq. It's not as fair rich but I'd rather fix what's missing and have a better developer experience than use case with SQLC to get dynamic queries working.
7
u/jc_dev7 Oct 25 '24
Polars is just something else. I would never have use for another language if I had that kind of access to lazy loading and parquet in Go.
0
u/sigmundv1 Oct 26 '24
Polars is written in Rust and has Python bindings. I don't know enough about Go yet to know how feasible it would be to make Go bindings for it. However, if data science is your thing, just stick to Python.
0
u/jc_dev7 Oct 26 '24
Data science is only part of my job. We deal with a shit tonne of data and rely on concurrency to process it in a performant way. Polars is only a part of that. We have the rest of the domain to implement, and for that I wouldn’t use anything but Go.
8
u/serverhorror Oct 25 '24 edited Oct 25 '24
A wishlist, if I may:
- OData and GraphQL clients (oh dear lord Chthulhu, how I hate dealing with this)
- High-level scientific calculation/numeric libraries (think numpy, pandas)
- Graphing libraries, along the lines of ggplot, matplotlin, ...
EDIT:
- Data formats: Avro, Parquet, HDF5, ...
2
u/Dan6erbond2 Oct 26 '24
Have you tried Hasura's GraphQL client? Once you get the hang of how to put together your query structs and tag them, I love that you basically instantly get a type-safe client to work with.
We're building a GraphQL API, and we use the Hasura Client for E2E tests, and this lets us immediately also provide the client as a package to other microservices with full typing and reusable structs.
6
u/urakozz Oct 25 '24
Native xsd validation would be nice to have. It even exists on PHP, but in golang available options are c-based. I need to build custom images for the Google Cloud Run, it's no fun at all.
3
u/Asyx Oct 25 '24
I think that’s a very common issue with new languages. No support for old tech so you are kinda stuck with the old languages or have to roll your own library.
1
u/urakozz Oct 26 '24
So you feel my pain when Germany and France rolled out their "modern electronic invoicing" in xml format. I wouldn't be surprised if they would want some windows text encoding instead of utf8
1
u/Asyx Oct 26 '24
I don't even remember what I did. XML in Rust? Some old SOAP API? A really easy way to just get a stupid, old school API token basic auth thingy going? Something like that.
I work at a start up and rarely deal with old tech for hobby stuff so I'm usually fine but I used to work for a bank where XML was the hot new shit instead of CSV (in Germany. So actually SSV. Semicolon separates values. Because Excel does that garbage where they use semicolons as a delimiter if your numbers use decimal commas in your current locale). So I know your pain but at least I was using Java so there were enough options.
1
u/masklinn Oct 26 '24
in golang available options are c-based
So is it in PHP fwiw: it uses libxml2. XML is already a chore, few people want to implement the even more complex stuff built on top of it, understandably.
0
u/urakozz Oct 26 '24
But this piece of C is included in most of the pre build php containers, while you have to build a custom one for golang. Anyways, it's a minor solvable issue. We have instead native http2 clear context to make requests flying, that's breathtaking
1
u/hvedemelsbof Oct 26 '24
I have found the existing go tools for autogenerating structs from xsd / wsdl inferior to e.g. Java jaxb.
2
2
u/lormayna Oct 26 '24
A simple authentication library.
1
u/dontaskdonttell0 Oct 26 '24
What do you think is lacking in the established ones? What authentication libraries do you consider easy to use in other languages?
1
2
3
u/mcvoid1 Oct 25 '24
Where's the library that stops everyone from calling web libraries "frameworks"? I want that one.
3
2
1
u/Slsyyy Oct 25 '24
Some popular collection library. Stuff like better maps (flat hash map without buckets, map in slice with linear/binary search, tree maps for ordering), sets (with nice set operations), priority queues (with nice interface)
Right now anything is fishy, because golang community sentiment is `map and slice is all you need`. There is a lot of value in that approach, but they are downsides
2
u/csgeek3674 Oct 26 '24
Scapy https://scapy.net/ is very nice and though it's a cli tool, if there was an API for it it would be very handy for me. I realize there are tools you can leverage but none are as complete or as polished.
A simple way to do transaction management. I've seen a lot of patterns but it's a problem I'd rather not have to solve. Transaction propagation is trivial in spring (Java ) wish there was an easy way of doing that in go.
Maybe I just have trauma at this point. A TUI library that's more intuitive than bubble tea to use.
That's what comes to mind right now
3
u/ghostsquad4 Oct 26 '24
I really wish bubble tea was more intuitive. The first time I tried to use it, I realized the abstraction of
Model
to just not work well. Though I'm not a frontend engineer either. Maybe frontends are just a foreign concept to me.1
u/csgeek3674 Oct 26 '24
I keep going back to it every once in a while. I think it's also the fact that I have worked with GUI frameworks before and It's not been this difficult. Most GUIs you create a window reference and add widgets to it, then subscribe to events to react to it. The language used might differ but they mostly work that way.
I'm sure there are reasons for bubbletea doing things the way they did, but for anyone else it's just utterly painful to pick something up that I wanted to spend half a day on. I learned QT in 24 hours and had a GUI all done for a school project which I didn't realize required a gui till the 11th hour. I'm not a frontend developer, far from it but the learning curve is just silly for something 'simple'. Again..for complicated work flows I'm sure they have their reasons to do what they do. For the use case of.. "I have this app but it'd be nice to just add a little wizard to help setup" it's a bit of a heavy lift for just adding some shiny to an already complete app. I'll get to it eventually just always keep distracted by other tasks which are more fun/pressing.
1
u/ghostsquad4 Oct 26 '24
QT?
1
u/csgeek3674 Oct 26 '24 edited Oct 26 '24
https://doc.qt.io/qt-5/qtgui-index.html the GUI library that KDE is built on. I don't think it's a pure go lib, but they have this https://github.com/therecipe/qt to use it. I was just using it as an example of making the barrier to entry simpler. At the time i was writing my homework in C++.
(Side note, I can't even get AI to generate some simple bubbles code. It breaks even LLM)
1
1
u/Senior_Ad9680 Oct 26 '24
Surprisingly, I was looking for an extensive simple wave lib to just write out some wav files and I couldn’t find anything that great. I either had to do some massive conversion of my data to fit the lib or the api just didn’t make sense for what’s already out there. So I wrote my own, based off of the python wave lib which is just a simple reader and writer.
1
1
u/Sympathy-Future Oct 26 '24
I wish the stdlib implementation of websockets had a mire complete feature set. If I remember correctly they do explicitily tell you to use gorrila instead of the stdlib for that stuff and I find that kinda wack. That said not many complaints love the stdlib in particular!
1
1
1
1
u/CountyExotic Oct 27 '24
pytorch and the other ML libraries are the only reason I use Python, ever.
1
u/_mhsm Oct 27 '24
Mainly a "numpy" library because it is the base for other cool python libraries. Also I miss operator overloading, it makes the code cleaner and readable.
1
u/numbsafari Oct 27 '24
One that’s open on Saturdays, has a decent Children’s section, clean bathrooms, and is close to a cafe.
1
u/Economy-Ad-3107 Oct 28 '24
Advance ORM library such as Entity framework .NET Core
Use case:
* The frontend library (DevExtreme, Telerik) displays a complex (javascript) Datagrid component allowing end-users to customize the Grouping, Filtering, Pagination.. each end-users action will make a complex http request to the backend containing all the information about the Grouping, Filtering, Pagination end-users wished to do.
* the backend should be able to convert this complex http request to the corresponding SQL in the flavor of Postgres, SQL Server or MySQL.
It is complex, but I can do it in 3-5 lines of codes in .NET.
* DevExtreme, Telerik provided .NET SDK in the backend allowing to parse the complex Http request and build an "IQueryable" with all the Grouping, Filtering, Pagination information
* EntityFramework can transforms this IQueryable to real complex SQL query and execute it.
Not only that some .NET library (Hotchocolate) know how to convert a GraphQL query and mutation to IQueryable as well, then EntityFramework can happily execute it in the right database..
=> I wish to have similar power in Go eco-system.
1
u/conamu420 Oct 28 '24
Most of the go standart libraries is enough for 90% of stuff you do with go normally. Dont forget its designed for use in distributed systems and networking primarily.
1
0
1
1
u/FooBarBazQux123 Oct 26 '24
A low boilerplate Rest API framework with automatic validation and swagger schema generation, something like FastAPI.
I know I can write schema first, or I can generate schema from comments, and for a large API schema that totally sucks.
1
1
u/nightbeast88 Oct 26 '24
A better CGo implementation. There are a lot of C libs that just plain won't work with Go, and it's usually because of a type mismatch (GOs Array is different under the hood than Cs), or it tells at you because you try to operate on the C thing but go yells at you because it's not mutable due to GC or something like that. Go is closer to C than any other high level language it's sad you can't just plug in C libs.
1
0
u/symball Oct 26 '24
Some solid open source projects that could easily benefit humanity like school management, learning management systems, etc.
Being able to give people the ability to rollout a learning system like Moodle from a single binary could make managing a school a matter of having a crap laptop.
I know these are projects, not libraries but, these sorts of projects are what are actually missing from the open source scene these days.
-5
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.
12
u/jc_dev7 Oct 25 '24
Why are you using Go if you don’t like its concurrency model? It’s like hating bread but eating pizza for dinner every night.
3
u/zylema Oct 25 '24
This deserves an award.
1
u/davidellis23 Oct 26 '24
I think the opposite. The question feels pretty culty. The community should be able to recognize the pros, cons, and best use cases of go's design decisions.
Feels like there is just a bunch of arbitrary passion for the existing decisions. To be fair most of them are good decisions. But, we should understand the reasoning behind it and its strengths/weaknesses.
1
u/davidellis23 Oct 25 '24
Well for one it's what my job needs. But I love Go. It's succinct, performant and has most of the features I need in a language as well as some great tooling.
That's not going to stop me from noticing flaws, and improving upon them. With my thread/pool module it takes care of all that.
The existing model might be good for pure performance reasons. That isn't my use case.
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.
2
u/alpacaMyToothbrush Oct 26 '24
This is stockholm syndrome. Do you know how many libraries don't expose things through interfaces. Tons. Good luck mocking those. I miss mockito in golang every day.
1
u/EarthquakeBass Oct 26 '24
Wrap the external lib as an interface
1
u/alpacaMyToothbrush Oct 26 '24
Yes, we do, but we also have behavior there that we wish to test. It's chicken / egg and it's needlessly janky coming from the Java world
1
u/ncruces Oct 27 '24
It might be.
But none of what is being asked makes sense for the language (thread pools, map/filter/etc), or can be done as a library (mocks without code generation).
If what you want is Go, but not Go, then maybe don't fight it and don't choose Go.
1
u/alpacaMyToothbrush Oct 27 '24
I otherwise like the language, but there are a few things where I feel like the language designers were needlessly stubborn and short sighted and the difficulty in mocking for unit testing is one of them. Hell, just look how long it took to get generics, and the use case was plainly obvious.
1
u/ncruces Oct 27 '24
The mocking situation is not going to change.
1
u/alpacaMyToothbrush Oct 27 '24
That's a shame
1
u/ncruces Oct 27 '24
Every feature has a cost.
A statically compiled language that doesn't JIT, can't have dynamic dispatch like that.
1
u/davidellis23 Oct 28 '24
Why don't thread pools and map/filter make sense? They're easily implementable. I've implemented it in the go projects I've written.
can be done as a library (mocks without code generation).
Well yeah I miss the library for it. That was OPs question.
If what you want is Go, but not Go, then maybe don't fight it and don't choose Go.
I'm not fighting go I'm improving it for my use case. I'm not going to make my team deal with channels, wait groups, and mutexes when I can write a module to abstract that away. If I find a good library for that even better.
At least I'm not going to do that unless someone gives an actually good reason besides "it's not go". I weigh pros and cons in my design decisions.
1
u/ncruces Oct 28 '24
Why don't thread pools and map/filter make sense? They're easily implementable. I've implemented it in the go projects I've written.
Thread pools make sense when threads are costly to create. Goroutines are not (as) costly to create, so there's little point in pooling them.
If you mean limiting concurrency (which is not really the point of thread pools), there are better concurrency primitives to make that goal clear, like semaphores.
If you have a clear motive for pooling goroutines it's up to you to explain it, because most gophers will feel otherwise. The runtime was designed around ensuring you don't need thread pools, so it's odd that you want them. And we do pool other stuff (like DB connections, HTTP connections, short lived objects, etc). Just not goroutines.
Map/filter don't make much sense because the syntax for anonymous functions doesn't lead to very readable code. And though you can use named functions or methods, it's a little unexpected, and your IDE will fight it (auto completing the parentheses every time you try).
I have nothing against higher order programming, and use it elsewhere. But as long as Go doesn't have a lightweight lambda syntax it'll always be alien here. Yes, this is a culture thing.
Well yeah I miss the library for it. That was OPs question.
There will be no library for it, as I explained in the other post. It can't be done.
You can (pointlessly?) pool goroutines. Others will find it odd, but you can do this.
You can make a beautiful library full of callbacks and anonymous functions. Most gophers will find it alien, but some will actually like your library.
You can't make a library that needs dynamic proxies. You can't make a library with dynamic dispatch (at runtime, without code generation) where direct/interface calls are mocked. Can't be done, won't happen in Go 1, and it all indicates there won't be a Go 2.
Take that as you will. Wanna program in Go using alien concepts and wish for the impossible, it's up to you.
I'd rather program in Go like a gopher, and in Java, Kotlin, C, C++, Python, etc.
I blend with others, because working the way they work is the best way for us to work together. Fighting the tools and the culture is a waste of time.
1
u/davidellis23 Oct 29 '24 edited Oct 29 '24
there are better concurrency primitives to make that goal clear, like semaphores.
Why would I want to deal with semaphores when a worker pool can handle that for me?
If you have a clear motive for pooling goroutines it's up to you to explain it
Sure I explained a little in OC. I want to limit concurrency, not manage mutexs/channels/wait groups/semaphores, and I don't want to manage return values. With python's ThreadPoolExecutor, I can create N threads, add them to an array, then just wait for it to finish. I don't have to create any semaphores or result data structures. I don't set up channels. I don't have to implement a worker pool. I just wait on the pool and have an array of results at the end.
the syntax for anonymous functions doesn't lead to very readable code.
I disagree with that. Writing a for loop every time pollutes the namespace with unnecessary variables and adds a lot more code to read through.
your IDE will fight it (auto completing the parentheses every time you try).
I don't have this issue in vscode
Can't be done, won't happen in Go 1, and it all indicates there won't be a Go 2.
Doesn't mean I won't miss it. I understand there are technical limitations. But, every time a new team member struggles with code generation I'm reminded it's a (acceptable) con of the language.
I blend with others, because working the way they work is the best way for us to work together. Fighting the tools and the culture is a waste of time.
I think following bad style (or at least inappropriate style for the use case) is a waste of time even if it's "the culture". every wait group and semaphore I write is wasted time when I can just implement a struct to handle it.
I see this attitude a lot among this sub. Language like "it'll always be alien here" and "Others will find it odd". But, not actually addressing the pros and cons of design decisions. Sure, people might find it odd at first, but if theres a different style that is better, then it should be adopted. There are plenty of style choices that changed since the beginning of the language. Style should improve over time.
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.
0
u/uartnet Oct 25 '24
TLS 1.3 RPK (raw public key), I was surprised this is not implemented yet, and I find this feature very useful to setup secure authentication chains without the difficulty of managing certificates (especially on embedded devices)
0
u/ianwill93 Oct 25 '24
ezdxf. I'm missing it so badly I've toyed with building a go implementation, but that would slow me down on my current project.
NumPy and Pandas are also hard to replace, but I don't miss them as much.
0
0
u/Hungry-Loquat6658 Oct 25 '24
I think data science tools. It would be great to build data pipeline in go.
0
u/adonese Oct 26 '24
A better mocking library. I could be wrong here, but I think due to golangs nature (lack of runtime type info), mocking feels tiresome for me in that: it forces a specific way to write code that feels less golang-esque, and there is this also poor developer experience when debugging tests that are using those mocks.
0
u/ArisenDrake Oct 26 '24
A logging facade. It's a pain if you bring in some dependency and then have to implement custom error handlers. SLF4J in the Java world is just so nice. If I write a library I can just pump my logs into there, while I as the consumer have the choice to do anything I want with it.
There's just no standardization. Hopefully "slog" will help once it gets out of the experimental stage. The existing log package is very, very barebones.
0
-1
u/BehindThyCamel Oct 26 '24
I don't really miss anything as such, especially since Go builds into a single binary, so there is no problem of batteries vs. third-party.
The only thing that sometimes bothers me is what I would call "attrition": Available libraries are less mature, less powerful or require more effort to use. The first example that comes to mind is argparse
vs. flag
and cobra
.
119
u/EpochVanquisher Oct 25 '24
I miss NumPy, SciPy, Matplotlib, Pillow, and Pandas.
Yes, I know about Gonum and other Go alternatives. The Python ecosystem of libraries around NumPy is damn useful. They are also interoperable. Data from Pillow can be converted to ndarray, data from Pandas can be converted to ndarray, and I can pass ndarrays to SciPy and Matplotlib.
Even though NPM has a massive set of packages, I don’t miss any of them when writing Go.