initpy / go-book Goto Github PK
View Code? Open in Web Editor NEWA book for learning the Go Programming Language
Home Page: http://go-book.appspot.com/
A book for learning the Go Programming Language
Home Page: http://go-book.appspot.com/
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
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!
On this page:
http://go-book.appspot.com/control.html
The link at the bottom for footnote 1 is now a 404 because of this:
https://groups.google.com/group/golang-nuts/browse_thread/thread/e6efaf1932c7b4a2
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
}
`
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).
http://go-book.appspot.com/slices.html#slice-shorthands
There is a "=" missing character in the next lines:
2: var array = [10]byte {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'}
21: b_slice = a_slice[:]
http://go-book.appspot.com/interfaces.html
Line 42 should be replaced by
s.loan += amount // (again and again and...)
instead of
loan += amount // (again and again and...)
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 {
}
)
"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
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.
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
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".
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)
Maybe someone knows author personally, he is not active since late 2012. I hope, he is fine and in good health.
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².
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 ")
}
}
}
}
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
}
Error: Not Found
The requested URL / was not found on this server.
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:
Line 42 in the function definition BorrowMoney()
loan += amount
should be
s.loan += amount
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'}
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)
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)
Dear all!
I'm afraid something happened to the author - he is not been online for 4 years on any his resources. Let's hope, everything is OK with him.
Meanwhile, anyone wills to step in and continue maintaining this book, so we can continue on a new fork and try to complete this book?
yelds = yields
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.