GithubHelp home page GithubHelp logo

golang-cheat-sheet's Issues

When to use pointers?

There is an example regarding pointers, but there is no comment that describes when to use pointers.

Functions As Values And Closures gives out whole bunch of errors

Hi, I'm new to go, but I can't compile source code from 'Functions As Values And Closures' chapter.
I had to change:
outer_var = 444 to outer_var := 444,
func outer() func() int, int{ to func outer() (func() int, int){
and in both another_scope and outer functions I'm facing undefined foo error. Am I doing smth wrong?
My go version output is go version go1.4.2 linux/amd64

Closures do modify outer variables

Hi,

I believe the example about Closures is not quite correct. The comment says that the returned outer_var is still 2 because inner() has only modified a copy of it. However, when outer() returns, inner() has not been called yet, and this is why outer_var is 2 at that time. When inner is executed before outer() returns, then outer_var is returned as 101. See this Playground test code: https://play.golang.org/p/e_wktwN6me

Thanks,
Christoph

ESP translation

Is it ok if I begin to translate the document to Spanish, or is someone else already working on it?

Adding common Go packages?

Would you be looking to add common Go modules to this guide, or is it no longer being maintained? I'd be happy to contribute.

Update your golang_refcard.pdf, please

outer_var in the outer func wasn't changed because the anonymous inner function hadn't been called yet.

// Closures: don't mutate outer vars, instead redefine them!
func outer() (func() int, int) {
	outer_var := 2 // NOTE outer_var is outside inner's scope
	inner := func() int {
		outer_var += 99  // attempt to mutate outer_var
		return outer_var // => 101 (but outer_var is a newly redefined
		//  variable visible only inside inner)
	}
	return inner, outer_var // => 101, 2 (still!)
}

I saw you made updates on the README file, but some people may also read your pdf file.

Add comment section

Personally, I think adding a "comment" section will be better for this cheat sheet.

typo in maps example

elem, ok = m["key"] // test if key "key" is present and retrieve it, if so

should actually be

elem, ok := m["key"] // test if key "key" is present and retrieve it, if so

You are missing a :

threads implementation specifics

Goroutines are lightweight threads (managed by Go, not OS threads).

Actually, the way goroutines are implemented are subject to the specific implementation. With gccgo, it does (or did?) use an OS thread for each goroutine.
from http://www.airs.com/blog/archives/448 :
"
On the functionality side, the gccgo library uses a single operating system thread for each goroutine. That is not what 6g/8g do: they multiplex goroutines onto operating system threads. Multiplexing is more efficient for a language like Go, and I need to change gccgo to work that way.
"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.