Code Monkey home page Code Monkey logo

go-book's Introduction

Welcome to the Go Book
**********************

This humble work (in progress) is an online book for learning the Go Programming
Language (golang) - It is meant for anyone interested in Go, and aims to be easy
and fun to read --despite my weak English.

You can read it online at: http://go-book.appspot.com 

It is written in reStructuredText and the rendering is done with Sphinx.

Your feedback is really appreciated :)

-Yuuta

go-book's People

Contributors

bbailey avatar case avatar cgt avatar hammerandtongs avatar initpy avatar mote0230 avatar oylenshpeegul avatar timonwong avatar wayneeseguin 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

go-book's Issues

Bugs in Getting funky with functions

There two bugs in this chapter in the section "The defer statement".

The func Contents definition is this (line 9):
func Contents(filename string) (string, os.Error) {

and should be like this:
func Contents(filename string) (string, error) {

See the second parameters is not os.Error, but error.

The other bug is in line 22:
if err == os.EOF {

Should be now:
if err == io.EOF {

And you have to add the io import at the beginning.

Greets and nice job!

Typo in Functions, why and how

In the section "How to do this in Go?", the output (results) values are named, but the names used in the code example differ from the names used in the bulleted list that explains the code.
2-8-2014 12-33-27 pm

Typo in Functions, why and how, #2

In "A function with a result variable", the code snippet used a var named 'squareroot' while the explanation refers to a variable named 's'.
image

Interface Section: Reduce verbosity when returning Boolean

Hi Big Yuuta,

Kudos! Great Work!

One minor style change I would like to request in your interface section for interface method(s) which return a boolean.

You write :
`

 func (g HumanGroup) Less(i, j int) bool {
       if g[i].age < g[j].age {
           return true
        }
        return false
   }

`
But the following is more concise, cleaner and is inline with Golang Idiom:

`
func (g HumanGroup) Less(i, j int) bool {

    return g[i].age < g[j].age 

}

`

Interface Type section:

You write:
Here, the interface Men is implemented by both Student and Employee.

However it should read:

Here, the interface Men is implemented by Human, Student and Employee.

Since all three structs make use of Men interface (Human embedded in other two).

Group declaration with Types

The Group declaration can be also used in more different situation like to declare type-aliasing,interfaces or structs:

type (
        //Type aliasing
    myMap map[string]interface{}
        //structs
    MyStruct struct {


    }
        //Interfaces
    TestInterface interface {

    }

)

Error in Chapter: Pointers and memory

"The sum of numbers from 0 to 10 is: 45
The double of this sum is: 90"

Actually, the sum of numbers from 0 to 10 is 55

Your loop only sums numbers from 0 to 9

for i:=0; i<10; i++{
    sum += i

Error on Slices page

On page http://go-book.appspot.com/slices.html

    a_slice = array[5:] // means: a_slice = array[5:9] thus: a contains: f,g,h,i,j
    a_slice = array[:] // means: a_slice = array[0:9] thus: a contains all array elements.

should be:

    a_slice = array[5:] // means: a_slice = array[5:10] thus: a contains: f,g,h,i,j
    a_slice = array[:] // means: a_slice = array[0:10] thus: a contains all array elements.

...because there are 10 elements, not 9.

var y, should it not then say y = 4 * Pi ?

page = http://go-book.appspot.com/first.html

In the section called "What is a constant?" the example says
"var y float32
x = 4 * Pi
//when compiled, y == 4 * 3.14"

At first I thought my programming was just terribly terribly rusty, so asked even geekier husband and he also thinks in my humble opinion that the x really should be a y???

ps love the tutorial

f instead of loater

On the functions page things are declared as floater and then the code try to access it as the variable f.
Guess someone did some really sloppy variablename changes


import "math"

//return A+B and A*B in a single shot
func MySqrt(floater float64) (squareroot float64, ok bool){
if floater > 0 {
squareroot, ok = math.Sqrt(f), true
}
return squareroot, ok

}

import "math"

//return A+B and A*B in a single shot
func MySqrt(floater float64) (squareroot float64, ok bool) {
if floater > 0 {
squareroot, ok = math.Sqrt(f), true
}
return // Omitting the output named variables, but keeping the "return".

}

Bugs in Slices Chapter

Last example of the slices chapter:

- newSlice := make([]byte, l+len(data))
+ newSlive := make([]byte, length + len(data))

Also, need to reassign after append, since we potentially return a copy.

- Append(hello, world)
+ hello = Append(hello, world)

Weird chars inside some parts

Hi,

first, I would really like to say a big thank you for your work on this book.

I have tried to use Sphinx to generate a PDF document (via LaTeX), but the compilation fails because of some weird chars (ie the chinese ones inside hello.rst).

Even inside my text editor (SublimeText2, using UTF-8), I cannot see them correctly. I've also tried to copy/paste those chars from the web, but it fails too.

Maybe I've done something wrong ?

Thanks again:

Kib².

Functions as Data section: change var name from "key" to "index"

Hi Yuuta,

In section "Functions As Data" you wrote the code below. Since activity is a slice and not a map you should refrain from using the word variable name "key", instead use variable name "index", since keys are associated with maps not slices or arrays.

Changing the name will make your code much easier to read and understand.

You wrote:

func compose(p phrases, a []activity) (func()){
    return func(){
        for key, value := range a{
            fmt.Print(p[value])
            if key == len(a)-1{
                fmt.Println(".")
            } else {
                fmt.Print(" and ")
            }
        }
    }
}

Should be corrected in following manner (see use of variable name "index" in place of "key")

func compose(p phrases, a []activity) (func()){
    return func(){
        for index, value := range a{
            fmt.Print(p[value])
            if index == len(a)-1{
                fmt.Println(".")
            } else {
                fmt.Print(" and ")
            }
        }
    }
}

Interfaces: Our Own Example Section Max function index for one element condition off by one

In "if-conditional" for one element statement in Max method change index from 1 to 0 for data.Get(x) ."

Currently your code "As Is" will generate following error for one element condition:
panic: runtime error: index out of range

You currently have the following:

func Max(data MaxInterface) (ok bool, max interface{}) {
    if data.Len() == 0{
        return false, nil //no elements in the collection, no Max value
    }
    if data.Len() == 1{ //Only one element, return it alongside with true
        return true, data.Get(1)
    }
    max = data.Get(0)//the first element is the max for now
    m := 0
    for i:=1; i<data.Len(); i++ {
        if data.Bigger(i, m){ //we found a bigger value in our slice
            max = data.Get(i)
            m = i
        }
    }
    return true, max
}

Should be corrected to the following

func Max(data MaxInterface) (ok bool, max interface{}) {
    if data.Len() == 0{
        return false, nil //no elements in the collection, no Max value
    }
    if data.Len() == 1{ //Only one element, return it alongside with true
        return true, data.Get(0)
    }
    max = data.Get(0)//the first element is the max for now
    m := 0
    for i:=1; i<data.Len(); i++ {
        if data.Bigger(i, m){ //we found a bigger value in our slice
            max = data.Get(i)
            m = i
        }
    }
    return true, max
}

Delete Map Key

http://go-book.appspot.com/maps.html#deleting-an-entry
The right way to delete a map key is:

delete(myMap, "Key") 

the other syntax in the go-book doesn´t work
assignment count mismatch: 1 = 2 (use delete)

and you have 2 typing errors:

  • You must call the map with the name not with the type
  • The same mistake in the lower description

Typo in Pointers and Memory

In the example output concerning the Hex address of the four vars, the hex values for var "i" and "hello" are the same. I thought they would be different. Right?

image

Advance Composite types: Slices

var array [10]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}

should be

var array = [10]byte{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}

,OK syntax usage

Awesome book!! It'd be great if you'd explain a little about ",ok" syntax and when it is generally used (i.e., stores the Boolean, etc)

maps

http://go-book.appspot.com/maps.html#how-to-declare-a-map

  • In the example, in line 9, numbers[3] should be numbers["trois"]

  • It isn't necessary to declare and then create a make a map

    var numbers map[string] int //declare a map of strings to ints
    numbers = make(map[string]int)

Instead:

var numbers = make(map[string]int)

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.