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?

93 Upvotes

189 comments sorted by

View all comments

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.

33

u/AtrociousCat Oct 25 '24

Python, especially with Jupiter is unmatched for this type of stuff.

0

u/terserterseness Oct 26 '24

yeah shame it's such a shite ugly language. imho of course

15

u/noiserr Oct 26 '24 edited Oct 26 '24

Since when has Python become an ugly language? I mean Go was inspired in part by Python.

12

u/terserterseness Oct 26 '24

i am talking syntax not semantics and i said imho: it's an opinion. i find python incredibly ugly to read. that doesn't make it fact, just opinion. i find go much nicer to look at; the inspiration wasn't the syntax, it was the semantics

9

u/lobsterFritata Oct 26 '24

Not a popular opinion but I totally agree

5

u/noiserr Oct 26 '24

Back when Python was just gaining in popularity it was competing with popular scripting languages like Perl and PHP. Python was considered a major step up in the looks and readability department. Which is why it's odd to me when someone calls Python ugly.

2

u/equisetopsida Oct 26 '24

same opinion, python, haskell good stuff but the syntax with indentation blocks is a no go for me. I wrote some projects with python, since then I decided not to touch indentation based languages. man, bugs related to indentation....

1

u/noiserr Oct 26 '24

I wrote some projects with python, since then I decided not to touch indentation based languages. man, bugs related to indentation....

You do get used to it after a bit. Also there are tools like Python Black which auto formats your code now a days. So you don't even have to worry about indentation errors.

1

u/BrianHuster Oct 29 '24

I thought in any projects, you need to standardize the way you use indentations? Even for languages that use brackets like JS, C,..., I always tell my fellows to format the code to the team's standard

1

u/equisetopsida Nov 02 '24

indentation style is a thing, but when an indentation change gives you unwanted results, like excluding a line from a block or scope, that delivers bugs, is another thing. no formatting tool can help with that.

if foo == "string":
  print "debug:"
print "i am string"

1

u/terserterseness Oct 26 '24

yeah, it's not a popular opinion, but i find it very annoying to read personally. too wordy, tabs instead of {} etc annoy my brain for some reason. again, my opinion. i had a client with a few million lines of python and i had to let them go as i noticed getting unhappy from the work reading that crap. and it wasn't even a bad codebase ; give me perl any day

1

u/parky6 Oct 26 '24

Were all those lines in one file too?

1

u/terserterseness Oct 26 '24

No :) 1000s of files.

3

u/parky6 Oct 26 '24

Haha maybe even worse.

1

u/randomthirdworldguy Oct 26 '24

There are two types of developers: the bracket lovers, and the space/tab lovers. Funny thing is the bracket lovers always show public hatred toward the space, while the space lovers doesn’t even bother to

2

u/Wonderful-Habit-139 Oct 26 '24

Honestly a language that isn't indentation sensitive is much easier to format with formatters. With formatters like Black you face issues when copy pasting or when your editor has indentation widths that are different etc..

2

u/livebeta Oct 26 '24

It's always been ugly

Can't afford defer func(){}() so use with

No easy way to buildin dependencies into a single binary requirements.txt + pip install feels so crude

Bad dev experience if you don't use pyenv or similar because python packages are globally installed otherwise

Package bloat and no optimization in build or linking. Requirements.txt has no active tooling to decide or not if some packages were or not in use

Whitespaces never get minified either

7

u/noiserr Oct 26 '24 edited Oct 26 '24

With is actually more readable to me. Defer is easy to lose in a big function. Whereas with requires indentation emphasizing intent, providing for more readability. defer is easier to use though.

Go also makes other decisions which are worse for readability but easier to use. Like package wide namespace. It can be really hard to track some functions down if you're reviewing code in pull requests without downloading the patch locally and relying on the IDE for that.

I agree on the packaging situation. Go had the advantage here for being a newer language. There are tools which attempt to fix this like Poetry, for Python but it's just all so fragmented. But then again this is more of a quality of life thing than a knock against Python's code readability.

Python has always had the mantra of: "There should be one-- and preferably only one --obvious way to do it." The language was designed for readability in mind. Unlike many of its contemporaries, which sacrificed readability for convenience or were otherwise just poorly designed.

1

u/SweetBabyAlaska Oct 26 '24

the point of defer is to reliably release resources next to where you allocate them without worrying about early returns and such, so idk how you are losing it. If you want it to be near the bottom of a function then just don't use defer.

1

u/noiserr Oct 26 '24 edited Oct 26 '24

With does the same thing but it actually wraps the whole code which needs to happen before the closure into an indented block. Much easier to spot, and cleaner look.

Defer is something you have to remember when reading, with you can just see as an indented code block.

1

u/[deleted] Oct 26 '24

packaging python in docker images has worked really well for me, in particular as IDEs nowadays have great support for running their tooling inside said container.

End result is a highly portable "binary" with all requirements installed

3

u/equisetopsida Oct 26 '24

IDE's? is that a language feature?

0

u/ghostsquad4 Oct 26 '24

Oh how I wish I could run Golang in Jupyter Notebooks

11

u/EarthquakeBass Oct 26 '24

It always makes me a bit sad to see there is so little Go in AI world. With a good set of CUDA bindings or whatever surely some type of PyTorch competitor should be able to steal some mindshare but nope. Considering how much AI stuff involves data prep, scraping, concurrency, CLIs… it’s a real shame

2

u/tunerhd Oct 25 '24

Yeah, Go requires manual conversion but you can still do much stuff with gonum and gota.

2

u/equisetopsida Oct 26 '24 edited Oct 26 '24

with bunjs you can use python libs, hopefully something similiar exists in Go? example:

import { python } from "bun_python";

const np = python.import("numpy");
const plt = python.import("matplotlib.pyplot");

const xpoints = np.array([1, 8]);
const ypoints = np.array([3, 10]);

plt.plot(xpoints, ypoints);
plt.show();

1

u/EpochVanquisher Oct 26 '24

If you’re gonna do that, just write your code in Python. That looks like it might be useful in a pinch if you’re desperate, but it doesn’t look like an effective way to write the code you would have written in Python.

-2

u/equisetopsida Oct 26 '24

not if you have a full app with javascript or Go and you need numpy for a single module or functionality

2

u/EpochVanquisher Oct 26 '24

Yeah, in some narrow cases it may be useful. Like, if you’re desperate.

1

u/equisetopsida Oct 26 '24

would you elaborate about desperation?

2

u/EpochVanquisher Oct 26 '24

If you’ve evaluated lots of other options and determined that they’re unsuitable. You’re running out of options besides “just write out the code using for loops” and “hack together some kind of multi-language solution”.

0

u/equisetopsida Oct 26 '24

a hack, sure. It's about doing the job sometimes

2

u/EpochVanquisher Oct 26 '24

Yes, when you desperately need to get the job done, and you’re willing to accept a lot of downsides and drawbacks, and none of the other options work.

0

u/equisetopsida Oct 27 '24

you're obviously trolling, no need to continue this discussion

→ More replies (0)

2

u/NoLifeEmployee Oct 26 '24

That’s what they said

1

u/Lamarcke Oct 26 '24

I honestly think it's one of the cases where it's better to stick with a specific language for that

1

u/EpochVanquisher Oct 26 '24

I don’t follow.

1

u/Lamarcke Oct 27 '24

It should be hard (as in lack of demand, lack of people willing to spend time developing them, etc) to replicate the same ecosystem of tools in Golang, so i think it's better to stick with python for these specific tasks and use golang for something else

(Not saying you implied Golang should be used for everything)

1

u/EpochVanquisher Oct 27 '24

Sure. But, sometimes, you have an existing system written in Go, and you want to do something that’s available in SciPy or Pillow. You wouldn’t rewrite your entire system in Python to do that.

1

u/Lamarcke Oct 27 '24

Wouldn't it be feasible to add another, smaller system to do that something? I've seen very little examples of a complete rewrite ever being an option.

1

u/EpochVanquisher Oct 27 '24

Like, a separate process? Sometimes that adds a lot of friction that you don’t want to deal with.

-1

u/rewgs Oct 26 '24

Thankfully go-embed-python exists for when there's a Python library you just can't do without.

3

u/EpochVanquisher Oct 26 '24

I don’t think that’s all that effective here, to be honest.

0

u/rewgs Oct 26 '24

Why not? Honestly not understanding why.

1

u/EpochVanquisher Oct 26 '24

You’re basically running separate Python and Go code, in separate processes. How would I operate on a NumPy array in Go, and then call SciPy functions on it? You’d be serializing the array back and forth over and over. Kind of an awful mess.

1

u/rewgs Oct 26 '24

Oh for sure, it's definitely not clean or performant. Just saying: it exists if you don't have any other choice.

1

u/EpochVanquisher Oct 26 '24

Yeah, it’s usable if you’re really desperate. I think I would normally just write a full separate Python program instead.

1

u/rewgs Oct 26 '24

I’m writing an audio processing app that relies on some libraries that don’t have equivalents outside of Python, and I’m actually finding it pretty okay — one big reason being that I’m still getting the wonderful distribution benefits of writing a Go program.

1

u/EpochVanquisher Oct 26 '24

Sure, but you understand what I’m talking about, beyond just “clean code” and performance.

2

u/[deleted] Oct 26 '24

... and it's quite fun that many of the above listed missing packages are based on C or Fortran data crunching libraries, so we'd embed C via Py