Giter VIP home page Giter VIP logo

book's Introduction

Go Bootcamp Book

This is the support book for Go Bootcamp events. Go Bootcamp Everything you need to know to get started with Go. Feel free to fork and send pull requests.

book's People

Contributors

alexwheeler avatar brianhall avatar campoy avatar damonkelley avatar diemer avatar dolphin8 avatar erbesharat avatar gnagno avatar gvarisco avatar heroiceric avatar humboldtux avatar jaimeiniesta avatar jipiboily avatar johennes avatar jppunnett avatar k4rtik avatar kylecrum avatar kytrinyx avatar lukasbacigal avatar marine675 avatar mattagohni avatar mattetti avatar mauricioschneider avatar nickmerwin avatar ripounet avatar romul avatar sindice avatar tapank avatar utzig avatar xercoy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

book's Issues

duplicate argument error

I'm getting a 'duplicate argument name' with the below code

func location(name, city string) (name, continent string) {
    switch city {
    case "New York", "LA", "Chicago":
        continent = "North America"
    default:
        continent = "Unknown"
    }
    return
}

func main() {
    name, continent := location("Matt", "LA")
    fmt.Printf("%s lives in %s", name, continent)
}
go version go1.4.2 darwin/amd64

Bitcoin exercise (exercise_loops_and_funcs) is incorrect

In your Bitcoin exercise, you calculate the number of coins for "Augustus" as 10, when it should be 13, leaving you with -1 coins. I'd submit a pull request, but I'm not sure if you'd rather use a different name, increase the # of coins, etc.

2.7 Code snippet -> Named return params

func location(name, city string) (name, continent string)
should be

func location(name, city string) (region, continent string)

Running the current cod in the playground will return:

prog.go:5: duplicate argument name

However, the linked playground code is correct.

Repos on setup location moved from code.google.com

Following the setup in Chapter 9, I found the repos at the bottom have moved from code.google.com.

Stevens-MacBook-Pro:go cittzl$ go get code.google.com/p/go.tools/cmd/godoc
the code.google.com/p/go.tools/cmd/godoc command has moved; use golang.org/x/tools/cmd/godoc instead.

Stevens-MacBook-Pro:go cittzl$ go get code.google.com/p/go.tools/cmd/vet
can't load package: the code.google.com/p/go.tools/cmd/vet command has moved; use golang.org/x/tools/cmd/vet instead.

diff source book and online book

Please compile new version for online book

I found,
Chapter 2: The Basics |> 2.7 Functions, signature, return values, named results
The content of online book , still old than source book

Type assertion

2.7 Type Assertion

package main

import (
    "fmt"
    "time"
)

func timeMap(y interface{}) {
    z, ok := y.(map[string]interface{})
    if ok {
        z["updated_at"] = time.Now()
    }
}

func main() {
    foo := map[string]interface{}{
        "Matt": 42,
    }
    timeMap(foo)
    fmt.Println(foo)
}

Here, timeMap func is a magic to me. You neither specify any return value for this nor pass a pointer to it while calling, but it is working fine. Can you explain the logic in it?

Thanks
p.s Your book is awesome!

3.3 Type assertion - assumes interfaces and structs understood

You introduce the idea of type assertion with examples of interfaces and structures.

  1. these are complicated syntactical examples that are difficult to understand in the realm of the basic language. Dot notation with some shit in-between parens:

y.(map[string]interface{})
value.(type)

  1. the reader has not been introduced to the concepts of interfaces or structs yet so it cannot be understood in this sequence.

Consider moving this section to advanced concepts and perhaps referencing this:

ex 3.3 Type assertion

"for more advanced subject of type conversion, please see section 2001.1" etc

EDIT: I think the whole document could use a good edit so that the examples and subjects flow with what is learned. Throughout the book, examples are presented using concepts and techniques that have not yet been introduced and explained, therefore it frustrates.

Translate PT-BR

Hi everyone! Exist any translating to portuguese Brazil? I'm desiring get started!

Concurrency : leaks in Equivalent trees solution

Hi Matt
As stated in PR #38, we still have a problem of goroutine leak and channel leak. Some Walk invocations will never return because they are stuck writing in a channel that is not read anymore. I revealed the leaks on my computer by calling Same a large number of times on different trees : the memory footprint of the program, as shown by top, kept growing and growing.

Below I will suggest two possible fixes.

My feeling about concurrency in Go is :

  • it makes writing correct concurrent code easier than in other languages ;
  • it doesn't prevent from shooting oneself in the foot ;
  • it doesn't change the fact that concurrent design in general is difficult and subtle ;
  • goroutines and channels have their own subtlety, that we must be aware of ;
  • we should stick to the convention that "the writer closes the channel when it's done writing" (and not "the reader closes the channel when it's done reading").

Possible fix 1 : "drain" the channels after use, i.e. loop to read all the potential unused values in ch1 and ch2. So we ensure recWalk will finish and Walk will close the channel, so the goroutines can properly end and the channels will be garbage collected.
Advantage : it is short and straightforward to implement.
Drawback : completing the Walk of a big tree is an undesirable amount of work when the tree comparison returns false early : we should not have to process the remainder of the tree.

Possible fix 2 : create a quit channel for each tree, as described in this slide.
Advantage : no more leaks, no useless work.
Drawback : the code is lengthier and more difficult to write and read.

What do you think?
I can make a pull request for (fix 1) or (fix 2) of the go code, and the paragraph would need to be updated to explain the plumbing.

Cheers

Dead imports from code.google.com

Hi,

there are a couple of dead links in the book, which reference code.google.com.
These packages seem to be moved to golang.org.

I will fix this and create a PR for that.

Mattagohni

Chapter 2.7 Code Example is Incorrect

In the book, the example is shown as

`func location(name, city string) (region, continent string) {
switch city {
case "New York", "LA", "Chicago":
continent = "North America"
default:
continent = "Unknown"
}
return
}

func main() {
region, continent := location("Matt", "LA")
fmt.Printf("%s lives in %s", region, continent)
}`

But, the Go Playground shows

`package main

import "fmt"

func location(city string) (region, continent string) {
switch city {
case "Los Angeles", "LA", "Santa Monica":
region, continent = "California", "North America"
case "New York", "NYC":
region, continent = "New York", "North America"
default:
region, continent = "Unknown", "Unknown"
}
return
}

func main() {
region, continent := location("Santa Monica")
fmt.Printf("Matt lives in %s, %s", region, continent)
}
`

The Playground seems to be more correct than the code shown in the book text.

Concept of "interfaces" covered before chapter 7

Section 3.3 we are covering Type Assertion http://www.golangbootcamp.com/book/types#sec-type-assertion.

The examples in the book are going over interface type assertions. I, being new to go, don't quite understand interfaces yet. So these examples are not helpful at all.

It would be better if:

  1. we covered what an interface is before section 3
  2. used a different type in the examples.

Similarly, in this example we are also going over maps which aren't covered till the next section in section 4.

Maybe Type Assertion should be moved to after all these other concepts have been covered. So that the code examples aren't so confusing to new go programmers.

License?

What license is this awesome book under? Could you add a LICENSE file with this information?

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.