zoukankan      html  css  js  c++  java
  • Effective Go(官方文档)笔记

    Effective Go(官方文档)笔记

    1. 自己主动局部变量提升(编译期完毕?):return &...;
    2. 内置函数:
      1. new/make
      2. copy, append
      3. delete
      4. range(这是keyword吧?由于后面没有())
    3. array是值对象
    4. slice:引用array
      1. 2维切片(略)
    5. map
      1. if seconds, ok := timezone[tz]; ok { ...
    6. func (f *File) Read(buf []byte) (n int, err error) { ...
      1. 注意这里给*File类型添加了一个Read方法,buf是传出參数(slice是引用!

    7. fmt.Printf("...%d...", 1); //C风格的;
      1. fmt.Printf(os.stdout, args, ...); //C++风格的?这里args须要实现io.Writer接口(序列化?)
      2.  %v, %#v
      3.  %T
    8. type MyString string
    9. switch t := t.(type){ ... //Go的执行时内省是怎么实现的?这意味着每个value/ref都包括了一个type域字段吗?
    10. 变參:v ...interface{} ==> v... (不加...的单独v可看作slice,可应用range操作)
    11. func append(slice []T, elements ...T) []T
      1. append:实际上不能在执行时决定T的类型。需编译器在编译时的支持(所谓的builtin函数)
    12. defer:推迟到func结束前运行。即使是panic(函数作用域。非block)
      1. C/C++/Java程序猿能够理解为func内部总体包以try{...}finally{...}?
    13. 枚举:const { _= iota  A B C ... }
    14. 变量组声明:var { ... }
    15. 每一个文件里的init():用于验证初始状态?
    16. sort回调:Len() int, Less(i, j int) bool, Swap(i, j int) //这相当于把排序对象当作一个C++里的RandomAccessIterator接口?
    17. 类型转换
      1. str := value.(string) //如类型不匹配则runtime error;
    18. net/http
      1. type Handler interface {
        ServHTTP(w ResponseWriter, req *Request)
      2. => 一旦有了Handler实例,向http注冊:http.Handle("/path", handler)
    19. tie a channel to web page ?

    20. 为func扩展方法:
      1. type HandlerFunc func(ResponseWriter, *Request)
      2. func (f HandlerFunc) ServHTTP(w ..., req ...) { f(w, req) }
    21. _ = fd //unused, WebKit/Chromium里常常能够见到这样的写法,未使用的变量显式标记。未用到的代码要删除
    22. Embedding(type的组合)
      1. type struct里能够直接增加其它type的名字,无需变量名字。此时相当于type traits的mixin了?
    23. Share by communicating
      1. Goroutines:the stack starts small(可动态调整的栈)——这可能就是Go支持大规模并发程序的原因了
      2. <-chan:等待完毕消息(自己主动堵塞)
    24. * for循环变量(设为i)是重用的?=>
      1. go func(i ...){ ... )(i) //传递进闭包,产生新的副本
      2. i := i //名字的shadowing(这个特性C语言是没有的。C++的namespace能够觉得类似?)
    25. Channels of channels
    26. 并行:runtime.GOMAXPROCS(ncpu)
    27. panic/recover
      1. recover在unwinding时运行,即defer func() {...}中。
  • 相关阅读:
    POJ 2112 Optimal Milking (Floyd+二分+最大流)
    hdu5444 Elven Postman
    hdu5442 Favorite Donut
    hdu5437 Alisha’s Party
    hdu5433 Xiao Ming climbing
    hdu5432 Pyramid Split
    Codeforces Round #316 (Div. 2) C. Replacement
    hdu5396 Expression
    hdu3506 Monkey Party
    hdu3516 Tree Construction
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6848138.html
Copyright © 2011-2022 走看看