Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 1.3 KB

functions.md

File metadata and controls

40 lines (32 loc) · 1.3 KB

Overview

  1. Key features of functions
  2. See also Methods doc

Key Concepts

  1. An executable code block
  2. Multiple arguments
    1. Passed by value (or pass an address by value)
    2. varargs supported
  3. Multiple return types
    1. Passed by value (or pass an address by value)
  4. All types pass by value & return by value
    1. Some types pass by address value (feels like pass-by-reference)
    2. eg. map, slice, channel, pointer, function args
    3. See Language spec
  5. No overloading
    1. Same as C, javascript, typescript, Python, ...
    2. Unlike Java, C++, ...

Idioms

  1. Use pointer receiver only when mutating

TODO/Unorganized

  • TODO: (higher order) accepting function as arg
  • TODO: (higher order) return a function
  • TODO: defer - https://go.dev/ref/spec#Defer_statements
  • TODO: named result param
  • TODO: init function (per file)
  • TODO: varargs
  • TODO: it's ok to return address of local var in constructor

Other Resources

  1. https://www.practical-go-lessons.com/chap-40-design-recommendations#methods-and-functions
  2. https://www.practical-go-lessons.com/chap-10-functions
  3. https://www.golangprograms.com/go-language/functions.html
  4. https://gobyexample.com/functions