5 ms·
The best Go source code is the stdlib. When you read stdlib code, you can be confident that nothing is there by accident. Every decision was made for a reason.
by nemo1618 6y ago
The best Go source code is the stdlib. When you read stdlib code, you can be confident that nothing is there by accident. Every decision was made for a reason. When you're learning, that's invaluable, because it means you can "dig" anywhere and be rewarded for it, whereas "digging" into most codebases will often be a waste of time.
Also, I would advise actively avoiding the big names you have heard of. A lot of products are successful despite having garbage code. And even more of them are successful despite having only decent code, full of stuff not worth emulating.
Try to identify people who have a lot of experience and a strong command of the language, then look at their most recent projects.
- thinkingkong 6y agoThe stdlib is the best for clarity. But there are some excellent examples of how to structure projects depending on what you're trying to build. Mat Ryer gave an excellent talk on writing HTTP Services. If you want a good example on how to write distributed systems then Hashicorps' projects are more or less gorgeous. https://medium.com/@matryer/how-i-write-go-http-services-after-seven-years-37c208122831 https://medium.com/@matryer/how-i-write-go-http-services-aft... https://github.com/hashicorp https://github.com/hashicorp
- matwood 6y agoTo add to your point, Nic Jackson from hashicorp has a bunch of how-to videos and presentations that I've found good also. https://www.youtube.com/channel/UC2V1SxXFUa5YxVJvTsrCgyg https://www.youtube.com/channel/UC2V1SxXFUa5YxVJvTsrCgyg
- bewuethr 6y agoHe also wrote a book: https://www.packtpub.com/product/building-microservices-with-go/9781786468666 https://www.packtpub.com/product/building-microservices-with... The book might be good, but my copy had a problem with spurious characters in every code block, but that seems to be fixed in later printings.
- dastx 6y agoGreat resource! Thanks.
- nemo1618 6y ago> Hashicorps' projects are more or less gorgeous Is there a particular piece of code (as in, a single package/file/function) that jumps out to you as "gorgeous?" When I look at a random Hashicorp repo, it strikes me an impenetrable labyrinth.
- aprdm 6y agoTry to add a new feature or see how some feature works, with consul I did some greps over some features I used and followed the code.. was able to put a merge request upstream changing a behaviour I didn't like (configurable) within 4h (that didn't get accepted and that's OK)
- alexeldeib 6y agohttps://github.com/hashicorp/memberlist https://github.com/hashicorp/memberlist Fairly idiomatic/clean
- tonymet 6y agoIt’s also one of the more readable stdlibs. I use it for idioms and snippets .
- matwood 6y ago> The best Go source code is the stdlib. As a golang beginner, the go stdlib is one the most readable stdlibs I've read through. The combination of gofmt, manageable language features, and idiomatic ways to do things make most go code fairly easy to read. I know go doesn't have a million language features, but readability after the fact is one of the benefits of this approach.
- sagichmal 6y agoThe stdlib is kind of a mess. One kitchen, many cooks, and everyone was learning how to put a five-course meal together as they went. There are some great bits -- package io and ioutil, for example -- but a lot of it is full of what we now understand are bad ideas, and the compatibility promise prevents anyone from doing anything about it. There is much better code to read. I second the recommendation of HashiCorp's stuff. Stay away from Docker and especially Kubernetes.
- geoah 6y agoCouldn't agree more. Cheney's response to why that is was "do as we say, not as we do".
- wbl 6y agoDo you have source / more details? There certainly are a few warts but overall it gets the job done.
- earthboundkid 6y agoFYI, ioutil is deprecated in Go 1.16. :-) They copied everything out of it and into io and os. It’s much cleaner actually once you get used to it.
- maerF0x0 6y agoAnother reason it is a bit of a mess is because of the no breaking changes promise. They have to keep ugly or deprecated interfaces unchanged, even into Go 2, iirc.
- phoinix 6y agoI second that. Stdlib is great to get a feel how the language works. Some small programs are always the best, if they are written by a good programmer. A cli game i study right now but in Rust. A small program with a lot of logic, but without all the graphics distractions. https://github.com/VladimirMarkelov/solkit https://github.com/VladimirMarkelov/solkit