Effective Go (Official document) notes

Source: Internet
Author: User

effective Go (Official document) Notes
  1. Automatic local variable promotion (compile time complete?) ): Return &...;
  2. Built-in functions:
    1. New/make
    2. Copy, append
    3. Delete
    4. Range (is this the keyword?) Because there is no back ())
  3. Array is a value object
  4. Slice: Referencing array
    1. 2-D slicing (slightly)
  5. Map
    1. If seconds, OK: = Timezone[tz]; OK {...
  6. Func (f *file) Read (buf []byte) (n int, err error) {...
    1. Note that this adds a read method to the *file type, and BUF is the outgoing parameter (slice is a reference!). )
  7. Fmt. Printf ("...%d ...", 1); C-style;
    1. Fmt. Printf (os.stdout, args, ...); C + +-style? Here, args needs to implement IO. Writer interface (serialization?) )
    2. %v,% #v
    3. %T
  8. Type MyString string
  9. Switch T: = T. (type) {...//go how is run-time introspection implemented? Does this mean that each value/ref contains a type field?
  10. Variable parameter: v ... interface{} ==> v ... (Do not add ...) Individual v can be considered as slice, can be applied with range operation)
  11. Func Append (slice []t, elements ... T) []t
    1. Append: Cannot actually determine the type of T at run time, need compiler support at compile time (so-called builtin function)
  12. Defer: Deferred until the end of the Func, even if panic (function scope, non-block)
    1. C/c++/java programmer can be understood as Func internal whole package with try{...} finally{...}?
  13. Enumeration: const {_= iota \ n A B C ...}
  14. Variable Group declaration: var {...}
  15. Init () in each file: used to verify the initial state?
  16. Sort callback: Len () int, less (i, J int) bool, Swap (i, J int)//This is equivalent to treating the sort object as a Randomaccessiterator interface in C + +?
  17. Type conversions
    1. STR: = value. (string)//If the type does not match the runtime error;
  18. Net/http
    1. Type Handler interface {
      servhttp (w responsewriter, req *request)
    2. = = Once you have the handler instance, register with http: http. Handle ("/path", Handler)
  19. Tie a channel to Web page?
  20. Extension method for Func:
    1. Type Handlerfunc func (Responsewriter, *request)
    2. Func (f Handlerfunc) servhttp (w ..., req ...) {f (W, req)}
  21. _ = FD//unused, webkit/chromium often see this type of notation, unused variables are explicitly marked, unused code to be removed
  22. Embedding (combination of type)
    1. The name of the other type can be added directly to the type struct, without the variable name, which is equivalent to the mixin of type traits?
  23. Share by communicating
    1. Goroutines:the stack starts small (dynamically adjustable stack)-that's probably why go supports massively concurrent programs
    2. <-chan: Waiting for completion message (auto-blocking)
  24. * The FOR loop variable (set to i) is reused? =
    1. Go func (I ...) { ... ) (i)//pass into the closure to generate a new copy
    2. I: = I//shadowing of the name (this feature C language is not, C + + namespace can be considered similar?) )
  25. Channels of Channels
  26. Parallel: Runtime. Gomaxprocs (NCPU)
  27. Panic/recover
    1. Recover executed at unwinding, i.e. defer func () {...} In

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Effective Go (Official document) notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.