7 ms·
How substantial is Go's standard library compared to Python's? I know Go has support for what I would consider to be the bare minimum for what modern standard l
by 7to2 4y ago
How substantial is Go's standard library compared to Python's? I know Go has support for what I would consider to be the bare minimum for what modern standard libraries must provide (http, crypto, time), but what about support of smtp, data serialization formats, etc?
I want an alternative to Python that can provide the same awesome batteries-included experience. I am also considering Nim but I want a language with a strong industry backing.
- heretoo 4y agoYou could consider Clojure. It is backed by the java ecosystem, which is substantial. Not quite the same as python's "batteries included" approach.
- mzi 4y agoJava has substantial industry backing, but you cannot argue that it has a battery-included standard library. But to answer the question: yes, Go has support for SMTP in net/smtp and a lot of different serialization formats in encoding/ You can browse it all here: https://pkg.go.dev/std https://pkg.go.dev/std
- zmmmmm 4y agoGroovy would be the most "batteries included" JVM language I think ... latest version even bundled YAML support in the standard library. Of course, it has all the downsides of a "kitchen sink" approach to language design.
- mseepgood 4y agoYou can browse the standard library here: https://pkg.go.dev/std https://pkg.go.dev/std > what about support of smtp Yes, https://pkg.go.dev/net/smtp https://pkg.go.dev/net/smtp > data serialization formats What you can find in the "encoding/*" subpackages: JSON, XML, Gob, CSV, ...
- thefounder 4y agoGo is a good alternative. It has support for smtp and data serialization formats. I highly recommend it. Using a single compiled binary for deployment will be a nice addition too. If you have patience to try it for 2-3 months you may fall in love with it.
- Arbortheus 4y agoOne of my favourite Go security features is the single binary output, it means I can build my binaries into a distroless base image container for running in K8S. It removes a huge attack and vulnerability surface that containers introduce. My team uses Go whereas the rest of the company heavily uses Python. Our vulnerability scanner tool detects hundreds of high score CVEs just in their container images. Comparably there have been times I haven’t updated our distroless base image for a year and there isn’t even a single vulnerability (this one: https://github.com/GoogleContainerTools/distroless/blob/main/base/README.md https://github.com/GoogleContainerTools/distroless/blob/main...) In terms of defending your software supply chain, eliminating the cruft that is required to run an interpreted language in a container make a a huge difference.
- doctor_eval 4y agoIronically the need to include a distro is true with Java as well. It’s not about running an interpreter so much as having your runtime living external to your code. Go has a runtime, of course, but it’s part of the binary.
- doctor_eval 4y agoI just want to second this. It takes time to love Go, but it’s worth the effort. Actually, the single binary alone is worth the effort. But it goes much deeper than that.
- bit_flipper 4y agoGo has probably the most extensive stdlib of major languages outside of Python (happy to be corrected on that). You can get a sense for what is available by looking here: https://pkg.go.dev/std https://pkg.go.dev/std. There is also the "pseudo stdlib" that is maintained by the Go project but for one reason or another is not available in the stdlib currently: https://pkg.go.dev/golang.org/x https://pkg.go.dev/golang.org/x
- yencabulator 4y agoHell, I'll argue Go standard library is more extensive and better than Python's. Case in point: HTTP. The batteries included in Python definitely reflect the era of their creation.
- donio 4y agoNo "outside of Python" qualifier needed.
- kaba0 4y agoJava seems to have just as much if not more available in its standard lib.
- derkades 4y agoThough some modern features are lacking, like a JSON parser or web server.
- harriet1 4y ago[dead]
- donio 4y agoGo's standard library is much better than Python's. Python does not actually provide what you list as bare minimum since the http library is not production ready. Go's net/http is and it's what most people actually use.
- rawoke083600 4y ago> know Go has support for what I would consider to be the bare minimum for what modern standard libraries must provide (http, crypto, time), Compared to sat Rust Go has a very large and practical std lib ! You can actually do something with it I/O wise. To save some of my karma points, Rust do have a big "community with crates"
- scaredginger 4y agoIn the land of C++, we have a sparse standard library and no standard package management solution
- dzikimarian 4y agoTry it. It has some quirks, but what sold me is that it has sane defaults almost everywhere. My first time with Go was one of the rare experiences, where I just wrote code in a new language (some cryptography, some interactions with rest APIs), and it just worked. No wrestling with obscure features, no hidden magic. Currently I use it very often for various side projects.
- fancybouncy 4y agoexcept for the date api... it took me a couple days to understand the silly idiosyncratic magic string to format dates.
- kroolik 4y agoIt's really annoying. Esp. For a person that uses golang occasionally, like me. Thankfully, Goland learned how to autocomplete these inside format strings.
- bkq 4y agoOn the contrary, I much prefer the fixed date of "2006-01-02T15:04:05" for formatting time strings. I find it much easier to write "Mon 02, Jan 2006", than what you would usually put for the strftime equivalent, "%a %d, %b %Y" (had to look it up, and at a glance it's not that obvious what it formats to). With Go, all you need to memorise is the date itself. Granted, coming from other languages it can take a bit of getting used to.
- zimpenfish 4y agoI wish they'd gone with 2001-02-03T04:05:06 (sub 16 for 24h, obvs) because that at least is in numerical order (and you can use +07 for timezone.) There's surely no date format in existence where month comes first and year comes last -after the time-. Or if they were stuck on 2006, 2006-05-04T03:02:01 but then you get +00 for the timezone which might be weird.
- rob74 4y agoThis is what the documentation has to say about it: > These are predefined layouts for use in Time.Format and time.Parse. The reference time used in these layouts is the specific time stamp: 01/02 03:04:05PM '06 -0700 (January 2, 15:04:05, 2006, in time zone seven hours west of GMT). That value is recorded as the constant named Layout, listed below. As a Unix time, this is 1136239445. Since MST is GMT-0700, the reference would be printed by the Unix date command as: Mon Jan 2 15:04:05 MST 2006 It is a regrettable historic error that the date uses the American convention of putting the numerical month before the day. Using the American convention is regrettable, but putting the year after the time is even more regrettable IMHO. Not sure which timestamp format does that? Plan 9?
- maurice2k 4y agoGo has one of the best stdlib I've come across. It's very well written and documented, the code is extraordinarily clean and easy to understand, even for advanced topics like cryptography (of course you need some fundamental understanding here). I think it's comparable to Python. Go's stdlib was one of the reasons I ended up with Go instead of Rust (might have changed; Rust had a lot community content, but not a comprehensive stdlib; last checked 3-4 years ago).
- bogeholm 4y ago> Rust had a lot community content, but not a comprehensive stdlib; last checked 3-4 years ago Still the case now (depending on your definition of ‘comprehensive’ of course). It’s an explicit non-goal of Rust to include “everything” (eg. http, crypto, random numbers) in std because of the stability promises - you can’t make breaking changes to std unless you’re fixing a soundness issue AFAIR.
- maurice2k 4y agoI was evaluating Rust for some cryptography use case and there were only "random" community libs available that lacked support here and there. And I actually had no trust in any of those libs. A stdlib must not contain everything but a solid cryptography lib is probably a good idea.
- maurice2k 4y agoLooks like the situation improved a bit: https://cryptography.rs/ https://cryptography.rs/ I would still like to have a more comprehensive or high level stdlib for Rust that is maintained by a core Rust team.
- SergeAx 4y agoWhat's wrong with Python that you want an alternative?
- vultour 4y agoDynamic typing. Dealing with structured data and (de)serialisation was a major pain. To me Go feels like a stricter python, still having enough freedom to do most things relatively easily, but not having to worry about what's being passed around.
- 7to2 4y agoI desperately miss static typing.
- thiht 4y agoDynamic Typing, Dependency management, Bundling, Speed
- SergeAx 4y agoInteresting, three replies and all about strict types. In my own experience moving to Go from PHP downsides was exactly strict typing and (de)serialization. It is a major pain to handle variable JSON schemas, especially in verbose multi-nested objects in Go without falling back to reflections, which is faux pas there.
- doctor_eval 4y agoI’m learning a bit of Django and I can’t believe how much ceremony is involved. Idiomatic Go eschews frameworks and - as a former Java developer - that is something I really like about it.
- r2vcap 4y agoI agree that golang's standard library is high quality, nice, readable, permissive license. I have had several experiences porting parts of the Golang standard library to other languages such as C++ and have really enjoyed it. Golang's standard library has rich tests, such as fuzz tests, so the results after porting were also easily verifiable.
- varispeed 4y agoIf I needed some admin interface etc I'd use Django and then everything else I'd write in Go. There were occasions where I'd write a service in Python and then rewrite it in Go. Never found that I needed something and it was lacking in the standard library. It's very fine experience. Then what I like the most is Go is extremely reliable. I had Go services running with a couple of years uptime, flawless.
- dgb23 4y agoIt’s extensive, web server focused, ergonomic and has well documented and sensible security defaults. In Go you can write a production ready, well tested, _concurrent_ web application with routing, auth, sql storage, html templating, image optimization, and so on without fetching third party libraries. And you’re not leaving official docs for it.
- kervantas 4y ago> with routing Don't you need some 3rd party lib for that (if you don't want to implement your own router)?
- jaitsu 4y agoAlmost. The sql package is just an abstract layer which requires a 3rd party module to provide the concretions. I guess the API is the same, but you still need a 3rd party lib :)
- metaltyphoon 4y agoMost people don’t use the flags package either and opt for 3rd party, like cobra.