Last active
August 29, 2015 13:59
-
-
Save 1000copy/10529655 to your computer and use it in GitHub Desktop.
go oo 。一点肥肉也没有的骨干。作者显然是一个喜欢手打代码,不用ide的人。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Why so thin ? | |
| // | |
| // function - func | |
| // semicolor no required | |
| // struct new easy : o := Owner{id:1,name:"lcj"} | |
| // define var so easy :o := Owner{id:1,name:"lcj"} | |
| // if () ,() no required | |
| // type cast with (type),.(int) etc | |
| // go 的struct,传值,在函数内修改的,只是堆栈上的副本,改了是无法影响函数之外的。 | |
| // 不容易发生深层嵌套。就像c# 那么,namespace / class /function ,至少三层。而go,member function 总是一层 | |
| package main | |
| import( | |
| "fmt" | |
| "container/list" | |
| ) | |
| type Owner struct{ | |
| id int | |
| name string | |
| rooms list.List | |
| } | |
| func do_fill(owner Owner){ | |
| // change no way | |
| owner.name = "sq" | |
| owner.rooms.PushBack(1) | |
| } | |
| func do_fill1(owner Owner)Owner{ | |
| // change ok | |
| owner.name = "sq" | |
| owner.rooms.PushBack(2) | |
| return owner | |
| } | |
| func (o *Owner) member_func(arg int)bool{ | |
| } | |
| func main(){ | |
| o := Owner{id:1,name:"lcj"} | |
| do_fill(o) | |
| fmt.Println(o.name,o.rooms.Len()) | |
| o = do_fill1(o) | |
| fmt.Println(o.name,o.rooms.Front().Value.(int)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment