Navigation Menu

Skip to content

Commit

Permalink
Updated GoLang (markdown)
Browse files Browse the repository at this point in the history
  • Loading branch information
braidn committed Sep 4, 2015
1 parent e8e6e96 commit 512ce7e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion GoLang.md
Expand Up @@ -108,4 +108,38 @@
* Methods can be defined on any type defined in the package
* However, methods can not be defined from another package or basic types
* Pointer receivers are favorable for methods due to not copying values on each call.
* Pointer receivers are also favorable because they allow the programmer to modify the pointer value.
* Pointer receivers are also favorable because they allow the programmer to modify the pointer value.

### Interface

* A kind of type that is defined by a set or collection of methods.
* These can be glue between structs and more simple/generic functions.
* New types can quickly implement these interfaces and get access to these functions.

#### Errors

* Errors are an interface that with a single `Error` method that returns a string.

### Concurrency

* Variables are not shared across goroutines and therefore prevent race conditions
* A goroutine is a lightweight thread managed by the Go runtime.
* These are created by using the simple `go` keyword
* Goroutines are also used to push items into channels without causing deadlock
* This occurs due to the main thread working on the channel and the groutine waiting

#### Channels

* Channels allow the sending receiving of values through the `->` operator.
* Data always flows in the direction of the arrow.
* Channels can be created using make: `ch := make(chan int)`
* These can be buffered, to do so add the length as a second argument.
* ex: `ch := make(chan int, 100)`
* Channels are unlike files, where they don't need to be explicitly closed

#### Sender and Receiver

* Senders are used to close a channel to indicate no more values are available/allowed.
* Receivers can test if a channel has been closed

* Buffered channels will only send to the block when the buffer is full.

0 comments on commit 512ce7e

Please sign in to comment.