
Effective Go - flexterra
http://golang.org/doc/effective_go.html
======
oofabz
I have been tinkering with Go for a couple months and I've been so impressed
with it I'm about to start a real production server using it. It has all the
low-level functionality of C with some very useful features added, like
garbage collection, string manipulation, new data types like slices and
channels, and of course threading.

The main downside is that there are not a lot of libraries available. If you
want to use the language you will find yourself using 3rd party wrappers off
github of unknown quality, and you will probably have to wrap some C libraries
yourself, because no one else has.

Also, both the garbage collection and the goroutine scheduler could use some
work. Like most other garbage-collected languages, Go's GC has to stop all
threads in the program while it does its work, causing milliseconds of lag.
This makes the language unsuitable for realtime work like a fast-paced video
game.

The goroutine scheduler works using a fixed-size thread pool. You have to tell
it how many threads to use - by default programs are single-threaded. It has
no ability to lower the thread count when the system is under heavy load, or
to raise the thread count when most threads are unproductively waiting on
network IO.

Despite these minor problems it is amazingly full-featured for a compiled
language, and amazingly fast for a full-featured language. They are actively
working on improving the garbage collection and they plan to improve the
thread scheduler.

~~~
luriel
I will just note that improvements to the GC and scheduler and other compiler
optimizations are already implemented and will be part of Go 1.1

Also, the Go stdlib is very rich and covers lots of stuff, I have rarely found
need for bindings to C libs unless it is OpenGL.

Which brings me to the point of games, there are already a couple of games
using Go, the GC pauses are not as big of an issue because the GC is good
enough (it is parallel) and in Go is easy to avoid generating garbage.

~~~
thebigshane
Questions for those more versed in Go's GC than I:

1) Let's say you want to do everything you can to avoid generating garbage.
What would some those techniques be?

2) There is no delete function is there (for memory deallocation, not hashmap
key removal)?

3) Is it possible to eliminate all garbage, and if so could you prevent the GC
from starting up at all?

Possible existing answers that are a bit above my understanding (C# and Python
spoil me):

<http://news.ycombinator.com/item?id=4231048>

<http://blog.golang.org/2011/06/profiling-go-programs.html>

[https://groups.google.com/forum/?hl=fr&fromgroups#!topic...](https://groups.google.com/forum/?hl=fr&fromgroups#!topic/golang-
nuts/Ir7ZrKLddTU)

------
krakensden
Is there some reason documentation on the Golang website has 57 upvotes?

~~~
melling
If I had to guess, it's because people are quite excited about the language
and they're interested in giving it some visibility. There's always lots of
new technologies, but very few gain wide adoption.

------
rogerbinns
Any idea why Go uses tabs for formatting? (A google search didn't provide the
answer but did suggest I may want to find out why God does!)

About the only good pro-tab stance I have seen is that it allows the viewer to
choose a level they prefer, but I would expect consistency would be far
better.

~~~
james4k
That was actually one of the questions asked during the "Meet the Go team"
talk at Google I/O. They joke around for a bit, but they end up giving some
solid arguments.

[http://www.youtube.com/watch?v=sln-
gJaURzk&feature=playe...](http://www.youtube.com/watch?v=sln-
gJaURzk&feature=player_detailpage#t=1735s)

Edit: If you're curious/interested in Go, it's worth watching the whole talk.

~~~
rogerbinns
The answer given was that individuals can then choose how many spaces they
want their tabstops set to, and this was mostly an accident not formal thought
out design. (I didn't see any other arguments given.) gofmt itself is of
course a very good idea.

I have been following Go along the years, but think they made a big mistake
with exceptions. In particular you have to manually write the code from where
an issue happens all the way to where it is handled. Exceptions as done in
other languages isn't the exact pattern that has to be followed - it is the
writing of the boilerplate code that bugs me. Heck they could do something as
simple as if the error value returned is not used in any way then an automatic
'return ...vals..., error' is inserted after the call.

~~~
thebigshane
I'm curious if you have used panic/recover to see if it fills the perceived
void. (I'm not saying they do, I don't know)

<https://code.google.com/p/go-wiki/wiki/PanicAndRecover>

<http://blog.golang.org/2010/08/defer-panic-and-recover.html>

<http://dave.cheney.net/why-go-gets-exceptions-right>

~~~
rogerbinns
Thanks for the links, and panic is the usual retort. My problem is with the
boilerplate between methods. If A calls B calls C calls D calls E which can
have issues that A wants to handle (eg try a different IP address) then all
the intermediary functions will need code like:

    
    
       foo,bar,err=callX(...)
       if err!=nil:
           return _,_,err
    

It is the last two lines of boilerplate that need to be present for virtually
every call that makes me uncomfortable. Developers will start forgetting or
not being diligent which causes problems. Also I think (but don't know) that
by the time A gets an Error it won't know what the stack trace is for the
original Error. (The stack traces are extremely useful for logging and
analytics not for program behaviour.)

Needing to write the boilerplate means it is left out. For example look at all
the hello world examples. Note how they all ignore any errors from the
println. C has exactly the same problem, and I'm disappointed that Go is
perpetuating this problem.

------
uvtc
The Go language seems to have some substantial documentation, which is great.
Though, throughout, the code snippets would look better with some syntax
highlighting.

