Hacker News new | past | comments | ask | show | jobs | submit login
Go by Example (gobyexample.com)
392 points by kercker on March 4, 2016 | hide | past | favorite | 72 comments



Go does have some nice, clean resources, provided by the core language group and users. I find golang.org to be quite helpful. If you're interested in learning Go, I suggest Go's A Tour of Go to start: http://tour.golang.org/welcome/1

There is a previous discussion of Go by Example if you want to mine the comments: https://news.ycombinator.com/item?id=7075515

There is also Effective Go for learning about, well, idiomatic Go: https://golang.org/doc/effective_go.html

And there is a previous discussion of Effective Go if you want to mine the comments: https://news.ycombinator.com/item?id=4285461


I second the recommendation Effective Go. It's a fairly quick read and routed me around a lot of poor design decisions:

https://golang.org/doc/effective_go.html


Are any of these for novice programmers?


How novice? You could try out the Go Tour [1.]; it's gradual and if you find yourself getting stuck, you can break and definitely use Google to find help.

[1.] http://tour.golang.org/welcome/1


The Tour is a great place to start. It's a good idea to complement the basics you learn there with the common gotchas. "50 Shades of Go" covers most of the major gotchas.


I can highly recommend "The Go Programming Language". I find it extremely well written, and worth every penny. http://www.amazon.com/gp/product/0134190440


I didn't love it. I found it a little inconsistent, and I didn't learn that much from it; most of the Go blog posts have more insight than the book does.

It's a fine introduction to the language! It's great that Go has a credible book. But if you're already familiar with Go, I think you can skip this.

Happy to hear if other readers had different experiences.


I looked forward to a complete chapter on IO (not unlike http://www.amazon.com/Programming-Language-Brian-W-Kernighan...), but didn't see one.

Perhaps a future edition...


For sure, it's like the "C and R" for Go. Plus the source code for the examples is on Github.

- Book Site: http://www.gopl.io/

- Book Example Source Code: https://github.com/adonovan/gopl.io/


You mean "K & R" for Go? :-)


Ah, yeah - too late to edit! Please accept my apologies.


+1. Excellent book. Nice pragmatic examples that not only showcase Go's features but are also interesting from the purely algorithmic angle covering pretty decent range from bit-twiddling to some rather involved math (by my standards of course).


Edit: This site is great, really good for people who haven't seen it. (Please stop downvoting me:))

Am I missing something here? This site is well known and I have been using it as reference for a long time.


That's why there's a voting system, if people are interested, it gets to the front page :-)

For me, I haven't worked with Go before so it's nice to see a resource like this as it's appealing as an outsider. Maybe it's the thing that pushes people from just hearing about something to actually try it out themselves.


Well at this moment there are two comments below you that command the site (suggesting this is the first time they see it), so. :)


(commend)


Thank you. :)


OP must be new to Go if he does not knows this website already. And the argument that people use in other submissions to justify a re-post or apparently irrelevant submissions does not works here because if you search "Go Examples" [1] in most web crawlers will return this website among the first results.

[1] https://www.google.com/search?q=go+examples


I didn't know about it and I'm glad someone posted the link.

It's common for old stories get reposted, and it's fine since it's impossible for everyone to be aware of everything all the time.


Everyone who at least couple of times googled for anything Go related knows this site. Should I post golang.org now, because there may be someone living under a rock?


I've been programming in Go for a few years now and I've never seen this site before.

It's quite possible that the specific search terms you use (eg I never include "example" when Googling about Go[1]) and Google's personalisation (eg favouring resources you've used previously) would result in different search results to what other people might receive.

[1] Since any resource offering help in programming will include example source code, I always considered the search term "example" to be redundant.


I have history turned off in google search. "golang slices" or "golang maps" has the site in top-5. vOv


Result #5 on a query that generic is quite far down when you consider that all of the top 4 results would equally answer the question. So many people might not get as far as gobyexample.com using your search term example.

Plus on queries that generic, a lot of people might just go straight to golang.org and re-read their docs.

Obviously this isn't the case for everyone, but it would explain why I've personally never heard of gobyexample.com before.


No. 1 on HN front page is an ominous sign to me.


Why is an actual programming-related link ominous? Not enough crypto-drama?


Ominous how?


I have to agree. It's not unlike submitting w3schools.com.


Really nice. I'd be better to have them in a single place, similar to http://coffeescript.org/

Better grepablity.


I started keeping personal one page notes on Github for languages I want to learn so that it's easier to be effective when I start a small project. Here are my Go notes:

https://github.com/melling/ComputerLanguages/blob/master/go....

My OCaml notes are a better example of what I'm trying to do:

https://github.com/melling/ComputerLanguages/blob/master/oca...


If you want quick introduction about some languages, there is also https://learnxinyminutes.com/.


> Go is an open source programming language designed for building simple, fast, and reliable software.

By the way, what would you use for complex, fast, and reliable software?


That depends a lot on what you mean by "complex". If your problem naturally and profitably decomposes into a pipeline of smaller, simple subproblems, Go can still be pretty nice to work with.

I wrote a (bad) compiler in it, and Go wasn't really any of the trouble I had with it.


Could you give an example of a program you think Go isn't suited to?


The compiler was straightforward to express in Go, but I wouldn't want to write a static analysis tool in it.

I don't especially love writing database-backed web applications in Go.


You could use Go. Simple here means that the language doesn't add unnecessary complexity, not that it is only suited for simple problems.


I think "simple" in that context means that the software should be as simple as the problem domain will allow, not necessarily that it's bad at building applications with complex needs.


A language with generics, e.g. OCaml, Haskell, Scala or F#. Once complexity reaches a certain level that's one of the tools you need to manage it.


Sometimes. Other times, generics are a tool that development teams use to amplify complexity.


Giving your team more powerful tools should always be a positive. If you don't trust them not to do harmful things with them then you have bigger problems.


It doesn't feel like that's a strategy that worked especially well for Scala or C++. Go isn't the only language that removes powerful tools: all the strict functional languages do too!


The issues that Scala and C++ have are far beyond just "having generics". Classical (ML-style) generics are an incredibly simple feature, much more so than, say, built-in channels.


I agree and I like generics, but I think it's hard to argue that generics have never made a complicated project more complicated.


I'd say typeclasses, templates, and variance have, sure. Those are separate features from generics in my mind. (But you could reasonably lump them all together under the heading of "generics" and I won't argue too much.) :)


It's worked exceedingly well for Scala from where I'm standing. There is no other language I'd rather be using.


If you read my comment carefully, you'll see that I was not in fact saying that people were wrong to like Scala. I like C, but I don't get irritated when people point out its innumerable flaws.


If you read my comment carefully, you'll see that I was not in fact saying that you were saying that people were wrong to like Scala. I think it's the best language available today and I think that's as a direct result of it being willing to put powerful tools in the hands of its users; therefore "It doesn't feel like that's a strategy that worked especially well for Scala" is, in my view, simply wrong.


I don't think I'm the first person to suggest that Scala introduced a fair bit of complexity with all the features it embraced, but, fair enough.


I would say "Go" (among others).

I think the author meant that Go is a simple means to design fast & reliable software.

That would certainly be my point of view, in any case.


Note that clicking the tiny gopher icon in the upper right of the code box will launch play.golang.org with that code. That's a good way to play with code and see results in your browser.


Thank you so much! Was looking for exactly something like this.


google.com

Edit: no, seriously, as the other commenter mentions: "This site is well known and I have been using it as reference for a long time." If looking for something like this, it would've been hard to avoid this. This post seems sponsored, or friends doing favours. Weird.


You're not going to win this fight. Content makes it the the front page of HN (and Reddit and other user-generated content sites) by getting upvotes. You just have to accept that you may see content that isn't new to you. If it is on the front page, that means enough people haven't seen it yet.

Edit: I have already seen the website as well, but I was glad to see it again because I could come to the comments section for some good discussion.


Great resource for beginners. Though I've noticed a trend when trying to familiarize myself with languages and Golang in particular: examples tend to be too simple and I've found myself struggling once I tried to create more "real-life" things with it (similar to hello world or server examples on Node.js).

Though this is most likely personal/anecdotal and the website is an invaluable resource for a beginner. Well done.


Perhaps one of these resources can show more advanced use cases: https://github.com/golang/go/wiki/Books

Have you read The Go Programming Language by Donovan and Kernighan?

- Book Site: http://www.gopl.io/

- Book Example Source Code: https://github.com/adonovan/gopl.io/


I highly recommend this book. I find it the best Go book out there right now. Manning's "Go in Action" isn't nearly as good as Donovan & Kernighan's work.


One of the things I absolutely love about Go is that the standard library is so readable and accessible. It's been a great resource for learning by example, especially for some fairly complex design patterns.


Agreed. I feel like the struggling when actually implementing the language for a real project/product is normal.

I think this is because programming languages are built with performance, readability, and writability in mind. I've yet to come across a programming language that was specifically built to make it easy to use to build a software product (plenty of frameworks though, ex Rails).


This is awesome! Thank you. This is especially helpful for programmers who are good at other languages and want to get a feel of go quickly over a weekend. Much easier to map the existing mental models built over-time to the new go programming semantics. Humans learn best by example and comparing the new stuff with what we already know.


I agree 100%. I had a similar desire, that is to get a feel for go without making a big time commitment. I went to the wikipedia page and read that it has something called channels that sounded kind of like FIFOs or perhaps something out of SystemC.

This page gives a much faster understanding of what the language is like.


As an aside: Holy heck, CloudFront. 14ms! That's like half the best RTT I get to my office right down the street.


I had recently started to write a short guide about writing webapps in Go,

https://github.com/thewhitetulip/web-dev-golang-anti-textboo...


This is a really nice resource and I've been wanting to look at Go for a while! Could anybody point at the sort of projects that the goroutine/channel infrastructure excels at in particular?


You can use goroutine ( call function prefixed with 'go' e.g. go foo() ) or channels, any where where you would use threads in languages like C/C++/Java.

Their terminology is concurrent programming. So you never actually spawn threads. But just declare your code to be able to run concurrently. So it will parallel process on multi cpu machine. Or just get scheduled in/out of cpu, when waiting for I/O. So very much like threads, but the mental/programming model is different.

Channels are particularly very useful, where you would use a thing like Barrier in Java, for threads to converge. In channels you get concurrency by message passing on channels.

So example application can be, crawl multiple sites concurrently and converge using channels.

In my experience its very robust, and once coded and tested, rarely(if at all) you face any weird bugs, e.g. Deadlocks/etc which you would, in explicit threaded programming. Not to imply that its not shoot-in-the-foot proof. But for a programmer having experience of multi-threaded programming, when one moves to this model, it seems more intuitive and robust.

Edit: I see other programmers have endorsed http://tour.golang.org/welcome/1 . I second/third them. IMHO that's the best resource to learn Go (and from your browser). After I did the 70 or thereabouts exercises, over there, I attained Nirvana :-) , and didn't need anything else. Of course apart from golang pkg docs. And one piece which confused me in the beginning was slice/array. Its very easy, once you get a hang of it. Another thumb rule I follow is always have pointers to struct in slices or maps. To avoid, the costly copy. May be its obvious in hindsight, but wasn't to me, in the beginning, as sometimes passed pointer to slice, having struct as values, to a function argument. On realizing what a foolish thing it was, as slice/maps are passed by reference, I started doing the reverse (i.e. slice as is, but having pointers to structs) :-).


By far one of the better ways to learn the syntax of Go.


are there websites like this for other languages too? I really like the format of this.



I recently created this site for Elixir:

https://elixir-examples.github.io/


Sweet list. Thanks for posting.


Looks great - well done!


Dang, I was really hoping this was going to teach me how to play the game of Go, not how to program in the Go language.


Well maybe an example of something related to the game of Go written in Go should be planned in the future then. :)


I clicked expecting a go-the-board-game learning site.

I think I need to learn the rudiments of go-the-programming-language, just so I stop forgetting there's still something to disambiguate when I see the word 'Go' as a noun.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: