

Ask HN: Which are the best Go repositories to read to learn the language?
source link: https://news.ycombinator.com/item?id=25812021
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

I am looking at examples of real world professional usage for somebody already familiar with the language constructs and syntax.
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.

There is much better code to read. I second the recommendation of HashiCorp's stuff. Stay away from Docker and especially Kubernetes.




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.

https://medium.com/@matryer/how-i-write-go-http-services-aft...

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.



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.


But some of Go's language decisions only become clear once you've written a lot of Go
For example, the "var name = expr" declaration form seems unnecessary in light of the short ":=" form but it is in the language to allow indented declaration blocks like this (where some variables get an initial value and some get just a type):
var (
text []byte
last int
more = true
)
...
I've been using Go for 3 years and the more Go I write, the more I appreciate it. Enjoy

Another great read for learning go that covers the more traditional challenges of standing up a basic web service with user accounts, testing, metrics, etc. is https://github.com/benbjohnson/wtf and the accompanying blog posts that cover how to structure such an application and why.
I think the source code for pkg.go.dev is actually a treasure trove of good ideas and design patterns, especially if you are trying to make a small to mdedium sized web app (which, lets be real, is almost all web apps anyone will ever make). https://github.com/golang/pkgsite
I agree with the other commenters that stdlib is excellent for delving deep into the language.
Please avoid: Kubernetes, AWS code.
As a rule of thumb - less imports is better.



There are a few disturbing things:
1) Usage of `utils` package. Points against it were made in:
https://dave.cheney.net/2019/01/08/avoid-package-names-like-...
https://github.com/golang/go/wiki/CodeReviewComments#package...
2) Check out the number of dependencies. This looks almost like NPM hell.
3) Lack of standardization and consistency. This project is so big, and there are so many contributors with their coding styles that the project looks untidy.
4) A lot of import renaming is a symptom of package name clashing or simply poor package naming. You usually do not need to rename import, and this is simply not required if your package structure was carefully thought about.
Again, k8s is great. K8s solves a lot of problems. I love it, but it is not a great example of Go code.

Basically they've reinvented the wheel a bunch of times and now it's too late to import stdlib.Wheel =)


I've been intending to look up Golang on the site but I forgot until now. Thanks!
This is my result:
To see examples of good source code just click thru the function names when searching the documentation. E.g. https://golang.org/pkg/net/http/#NewRequest They link directly to the source code, and the standard library is extremely well commented.

Search:
Recommend
-
19
Sunday, 03 January 2021 00:29 Which programming language and technologies should you learn in 2021? Featured By
-
6
-
9
To Learn a New Language, Read Its Standard LibraryOctober 23rd 2021 — 0 CommentsThe best way to learn a new...
-
6
-
8
Ask HN: How many hours a day/week to you read books? I try to always read a chapter of my book before bed every night. Most of the time I enjoy it, sometimes it feels like a chore,...
-
10
Ask HN: What's the best book you read in 2021? Ask HN: What's the best book you read in 2021? 313 points by
-
8
How I decided which language I should learn Like many of you, I also thought for a long time about which programming language I should actually learn. Python for machine learning and AI, Java for big apps, Swift for mobile apps, each...
-
6
Ask HN: Best free software to read text aloud
-
3
Published 4 January 2023 Updated 4 January 2023 /
-
11
Top 5 Books to Learn JavaScript in depth -...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK