functions/

directory
v0.0.0-...-ae246d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2016 License: Apache-2.0

README

Functions

Functions are at the core of the language. They provide a mechanism to group and organize our code to separate and distinct pieces of functionality. They can be used to provide an API to the packages we write and are a core component to concurrency.

Notes

  • Functions can return multiple values and most return an error value.
  • The error value should always be checked as part of the programming logic.
  • The blank identifier can be used to ignore return values.

https://golang.org/doc/effective_go.html#functions
http://www.goinggo.net/2013/10/functions-and-naked-returns-in-go.html
http://www.goinggo.net/2013/06/understanding-defer-panic-and-recover.html

Code Review

Return multiple values (Go Playground)
Blank identifier (Go Playground)
Redeclarations (Go Playground)
Anonymous Functions/Closures (Go Playground)

Advanced Code Review

Recover panics (Go Playground)

Exercises

Exercise 1

Part A Declare a struct type to maintain information about a user. Declare a function that creates value of and returns pointers of this type and an error value. Call this function from main and display the value.

Part B Make a second call to your function but this time ignore the value and just test the error value.

Template (Go Playground) | Answer (Go Playground)


All material is licensed under the Apache License Version 2.0, January 2004.

Directories

Path Synopsis
advanced
example1
Sample program to show how to recover from panics.
Sample program to show how to recover from panics.
Sample program to show how functions can return multiple values while using named and struct types.
Sample program to show how functions can return multiple values while using named and struct types.
Sample program to show how we can use the blank identifier to ignore return values.
Sample program to show how we can use the blank identifier to ignore return values.
Sample program to show some of the mechanics behind the short variable declaration operator redeclares.
Sample program to show some of the mechanics behind the short variable declaration operator redeclares.
Sample program to show how anonymous functions and closures work.
Sample program to show how anonymous functions and closures work.
exercises
exercise1
Declare a struct type to maintain information about a user.
Declare a struct type to maintain information about a user.
template1
Declare a struct type to maintain information about a user.
Declare a struct type to maintain information about a user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL