
Go by Example - A_Ghz
https://gobyexample.com/
======
sergiotapia
It's Friday gents! No excuse to set aside Saturday and Sunday, you can easily
go through these examples in two days and grok it. Go is that _slim_, and
that's good!

Guaranteed you'll find use for Go in one system or the other when you want
easy deployment, fast development time and extreme speeds. :)

(Disclaimer: I love Go and I hope it goes mainstream in a big way in 5 years)

~~~
jamesaguilar
One nice thing these examples also do is make it really simple for detractors
to point out what they don't like about it. My #1 gripe about go, for example,
is this: [https://gobyexample.com/sorting-by-
functions](https://gobyexample.com/sorting-by-functions)

In a few other languages:

    
    
        // C++
        sort(vs.begin(), vs.end(), 
             [](const string& l, const string& r) -> bool { 
                 return l.size() < r.size();
             });
    
        # Python
        vs.sort(key=lambda s: len(s))
    

When they fix this, Go might be the perfect language for me. Until then, I'm
not touching it with a pole.

~~~
natural219
Wow, yeah. This is pretty bad. The example doesn't even make logical sense.
Why is ByLength a type? Shouldn't you just want to pass in an array?

Can any "idiomatic" Go programmers here give a better example of how you would
do this?

~~~
colin_mccabe
_Can any "idiomatic" Go programmers here give a better example of how you
would do this?_

Sure.

sort.Sort(sort.Reverse(sort.StringSlice(vs)));

~~~
colin_mccabe
Oops, I looked at the Python code again, and it seems to be sorting the
strings by their length, not reversing the sort order like I did. Sorry, I
didn't look at it very carefully earlier. Anyway, the easiest thing to do is
probably write a wrapper type around StringSlice using Go's anonymous struct
syntax. You only need to implement LessThan, since StringSlice already
implements the other two.

    
    
      type StringSliceByLength struct {
          sort.StringSlice;
      }
      func (s StringSliceByLength) LessThan(i, j int) bool {
          return len(s.StringSlice[i]) < len(s.StringSlice[j]);
      }
      Sort.sort(StringSliceByLength(vs))

------
tokenizerrr
This documentation is great, but one thing I tend to miss with examples like
these is how to structure a project, deal with packages, etc.

~~~
pearkes
GitHub is your friend here.

Here is a search for Go repositories with > 100 stars.[1] Every project will
look different (the really big ones might be more complex then you need) but
as you get deeper into the results you can find some great stuff.

[1]:
[https://github.com/search?l=go&q=stars%3A%3E100&s=stars&type...](https://github.com/search?l=go&q=stars%3A%3E100&s=stars&type=Repositories)

~~~
tokenizerrr
That's a great idea, I hadn't thought of that.

------
nadinengland
Another nice introduction is the Go Playground's Tour
([http://tour.golang.org/#1](http://tour.golang.org/#1)).

------
donbronson
The documentation format is a revolution of simplicity and comprehension. I
can see this list format (and content) working for any/all languages.

~~~
L8D
I'm in the process of making a clone of the site for node.js
[here]([https://github.com/L8D/nodebyexample](https://github.com/L8D/nodebyexample))

~~~
donbronson
Throws a 404. Is it a public repo?

~~~
L8D
Yeah, I trashed pretty quickly because I realized I didn't have time to work
on it, nor did I have the creativity to write good examples. It would have
better suited to be about JavaScript rather than Node, and there are already
plenty of better ways to learn good JavaScript on the internet. I might do
'Haskell by Example' which would be really fun, if I ever have time for it.

------
aaronbrethorst
Love it, bookmarked. I've been hoping for something like this for a while. One
of the most frustrating things for me about trying to pick up Go is a lack of
'guaranteed quality' examples of different basic operations, especially code
that adheres to the latest spec.

------
cupcake-unicorn
Are there any plans to make this into something more interactive, like
[http://nodeschool.io/](http://nodeschool.io/)? Alternatively, do any of the
interactive "Learn Coding" sites out there feature Go? I can't think of any.

~~~
steveklabnik
The tour does this: [http://tour.golang.org/](http://tour.golang.org/)

------
nickik
I am not personally interested in Go but I care about CSP. I will defently
check out some of these CSP things and maybe try to recreate them in Clojure
core.async.

------
namelezz
Golang is good language. Cannot wait until it's generic.

------
kirkbackus
It's about time! Go doesn't really have a good community or really practical
examples. Glad to see someone took the time to put this together.

~~~
insertnickname
> Go doesn't really have a good community

What about freenode/#go-nuts? Seems like a very nice channel to me.

------
vkat
Thanks, I am going to use this for my go experiments.

------
tboyd47
Hey, nice site. FYI I can't copy and paste from the examples on the site
without also bringing in the text on the left too.

------
knotty66
Nice and clean. I like it. Maybe it would be nice to have comments with
up/down votability ala Stackoverflow.

~~~
dclara
Such a nice UI. We all like fast food!

\- Eggs should not be washed.

------
holycow19
Very Cool - thanks

