Learn How To Code: Google's Go (golang) Programming Language

Learn programming from a University Professor in Computer Science with over 15 years of teaching experience.
4.5 (1,998 ratings) Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
42,950 students enrolled Bestselling in Go
$19
$35
46% off
Take This Course
  • Lectures 169
  • Length 21 hours
  • Skill Level All Levels
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 11/2015 English

Course Description

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Go is an amazing choice for a language as it was developed by some of the same individuals who created the C programming language, Unix, and UTF-8 - some of the most influential contributions to computer science. Robert Griesemer, Rob Pike, and Ken Thompson created Go to be a modern language that easily uses multiple cores, easily implements concurrency, easily works in distributed environments, and easily allows the programmer to write programs - it has a very lean and user-friendly syntax.

Go was created by luminaries in computer science at one of the best, if not the very best, software engineering firm to have ever existed - Google.

The credentials of Go are unsurpassed.

But why did Google create a new language?

In Google’s words, “Go was born out of frustration with existing languages and environments for systems programming. Programming had become too difficult and the choice of languages was partly to blame. One had to choose either efficient compilation, efficient execution, or ease of programming; all three were not available in the same mainstream language. Programmers who could were choosing ease over safety and efficiency by moving to dynamically typed languages such as Python and JavaScript rather than C++ or, to a lesser extent, Java. Go is an attempt to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aims to be modern, with support for networked and multicore computing. Finally, working with Go is intended to be fast: it should take at most a few seconds to build a large executable on a single computer. To meet these goals required addressing a number of linguistic issues: an expressive but lightweight type system; concurrency and garbage collection; rigid dependency specification; and so on. These cannot be addressed well by libraries or tools; a new language was called for.”

In my opinion, Go is the best programming language that you can be learning today. I began programming in 1982 with BASIC, I have worked with many languages, and Go is the best language which I have ever used.

Come learn about one of the greatest languages ever created. You will leave with resources and code samples to start making all of your software and apps really go.

What are the requirements?

  • No prerequisite knowledge is required to take this course. This course starts at the very beginning and will teach you everything you need to know to be an outstanding programmer.

What am I going to get from this course?

  • Learn how computers work
  • Learn the fundamentals of programming
  • Learn modern best-practices for programming
  • Learn from a University Professor in Computer Science with over 15 years of experience teaching individuals of all ability levels
  • Understand why the Go programming language is the best programming language you can learn today
  • Acquire additional valuable programming skills including understanding environment variables, using a command line interface (CLI) terminal, understanding SHA-1 checksums, working with GitHub, and increasing your productivity with an integrated development environment (IDE) such as Webstorm or Atom.io

What is the target audience?

  • This is a first semester university level programming course.
  • This course is ideal for beginners wanting to learn programming.
  • This course is perfect for experienced programmers wanting a thorough introduction to the Go programming language.
  • This course is perfect for experienced programmers wanting to fill in gaps in their programming knowledge.

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

Section 1: Introduction
07:24

Gain access to many valuable learning resources: accessing github code samples, accessing powerpoint presentations used in my college and university go programming classes, accessing my other training videos for free, staying abreast of other great learning resources by following me on Twitter Todd McLeod

  • HERE ARE THE RESOURCES: https://goo.gl/PHKgO7
  • Resources
  • Github code samples
    • downloading zip
    • searching for code
  • Powerpoint presentations
  • Youtube Todd McLeod
  • Bill Kennedy’s book
  • Donovan and Kernighan’s book
  • Caleb Doxsey’s book
  • go by example
  • language spec
  • effective go
12:15

Comparing today's programming languages; the credentials of the Go programming language; reasons for choosing Go; companies using Go; people using Go (bye bye node.js); an example of the server load carried by a Chinese company using the Go programming language.

09:37

Hello World; basic program structure; the go playground; packages; standard library; golang.org; godoc.org;

code: https://play.golang.org/p/04Qiz0BH4N

  • hello world
    • go playground
      • formatting code
      • sharing code
      • run code
  • packages
    • code that is already written which you can use
    • imports
      • (importing a package)
  • documentation
    • golang.org
      • standard library
      • src
    • godoc.org
      • standard library AND third-party package
Section 2: Installing Go
03:12
A preview of what we’re going to cover in this section: overview of the Go installation process; GUI’s versus command line; command prompt vs terminal; DOS commands vs Unix commands; SHA1, hash algorithm checksums; the importance of having your workspace configured correctly; namespacing in go; you will learn how to configure either a windows machine or a mac in this section.
06:13

terminal emulator - github

Download github and change the settings to enable the “git bash” terminal so that we can run Unix terminal commands on a Windows machine.

  • download github for windows
  • open settings
  • choose “git bash”
  • open it and test it
  • basic terminal commands
  • ls
    • ls -la
  • cd
  • cd ../
  • pwd
08:48

download go; run sha1 checksum openssl sha1; uninstall any old versions; install new version

  • download go
  • sha1 checksum
  • uninstall old version
  • install new version
  • go version
08:48

Learn the importance of your Go workspace. Learn how to configure your Go workspace. Learn about namespacing, the importance of namespacing, and how Go implements namespacing.

  • one folder - any name, any location
    • bin
    • pkg
    • src
      • github.com
        • <github.com username>
          • folder with code for project / repo
          • folder with code for project / repo
          • folder with code for project / repo
          • folder with code for project / repo
          • ...
          • folder with code for project / repo
  • namespacing
  • go get
    • package management
06:51

An explanation of environment variables.

08:01
  • computer / properties / advanced system settings / environment variables /
    • googling for location on different windows versions
    • search box in windows
  • user variables vs system variables
  • GOPATH
    • copying the path from windows explorer
  • Setting a PATH variable to your bin
10:23
  • spotlight search
  • terminal
  • cd ~
    • users home
  • ls -la
  • hidden files
  • .bash_profile
  • .bashrc
  • nano
IMPORTANT - REGARDING LINUX VIDEOS THAT FOLLOW
Article
33:39
  • This video is a lecture by a guest speaker at my CSU Fresno class. It covers:
    • setup a linux machine
    • use a linux machine on digital ocean
    • SSH
    INSTRUCTIONS:
    https://github.com/GoesToEleven/GolangTraining/tree/master/27_code-in-process/67_digital-ocean_aerospike
12:43

This video is a lecture by a guest speaker at my CSU Fresno class.

INSTRUCTIONS:

https://github.com/GoesToEleven/GolangTraining/tree/master/27_code-in-process/67_digital-ocean_aerospike

21:41

This lecture is from a guest speaker in my CSU Fresno class.

INSTRUCTIONS:

https://github.com/GoesToEleven/GolangTraining/tree/master/67_digital-ocean_aerospike

04:32

Test your installation and, at the same time, get all of the sample code used in this training!

04:04
  • github terminal emulator
  • basic terminal commands
  • ls -la
  • cd
  • cd ../
  • pwd
  • env
  • sha1 checksum
  • go command
    • go
    • go version
    • go env
    • go get
  • Go workspace
    • bin
    • pkg
    • src
      • github.com
        • <github.com username>
          • folder with code for project / repo
  • GOPATH
  • GOROOT
  • namespacing
  • environment path variables

using go get to get the code used in this course

Section 3: Your Development Environment
01:51
  • IDE’s (integrated development environment)
    • WebStorm
    • Atom
  • Configuring Webstorm
  • Using Webstorm
  • go run, go build, go install
  • Understanding Github
  • Creating Your Own Repo
  • Using Github
09:07
  • IDE’s
  • Webstorm
    • plugins
    • golang plugin
    • creating a new project || package || library
    • GO SDK
    • themes
      • http://www.ideacolorthemes.org/home/
    • live edit
      • JETBrains IDE Support Chrome Plugin
06:34
  • keymap
  • I have found helpful
    • preferences
      • search (search box in preferences)
      • right margin
      • wrap, soft wraps, folding
      • emmet
    • show line numbers
    • terminal
    • local history
    • refactor / rename
    • find in path
    • reformat code
    • comment
    • surround with
    • VCS
  • ATOM
    • made by github
    • go-plus plugin
Article

You can use WebStorm for free as a student:

https://www.jetbrains.com/student/

09:03
  • creating a folder for your code
  • opening that folder with webstorm
  • selecting the Go SDK
  • organizing your code sequentially
    • naming folders with numbers first is NOT idiomatic
  • .idea folder
    • seeing hidden files in Windows
08:14
  • writing the program
    • code completion
  • seeing documentation and source code internals instantly within webstorm
  • terminal
    • go fmt
    • go run
  • setting your theme
05:47
  • documentation
  • go run
    • needs a file name, eg, go run main.go
  • go build
    • for an executable:
      • builds the file
      • reports errors, if any
      • if there are no errors, it puts an executable into the current folder
    • for a package:
      • builds the file
      • reports errors, if any
      • throws away binary
  • go install
    • for an executable:
      • compiles the program (builds it)
      • names the executable the folder name holding the code
      • puts the executable in workspace / bin
        • $GOPATH / bin
    • for a package:
      • compiles the package (builds it)
      • puts the executable in workspace / pkg
        • $GOPATH / pkg
      • makes it an archive file
  • go clean
07:37
  • git
  • github
  • history
  • github
    • code storage
    • code sharing
    • code collaboration
    • code versions
    • code searching
    • programmer assessing
14:23
  • windows
    • install git
  • Creating Your Own Repo
  • pushing code to github
    • from webstorm
    • from terminal
      • git status
      • git add --all
      • git commit -m “first commit”
        • first time - set remote repository (repo)

git remote add origin https://github.com/GoesToEleven/udemyTraining.git
git push -u origin master

  • git push
03:40
  • IDE’s
    • webstorm
    • atom
  • Creating Your First Project
    • creating a folder for your code
    • opening that folder with webstorm
      • selecting the Go SDK
    • organizing your code sequentially
      • naming folders with numbers first is NOT idiomatic
    • .idea folder
      • seeing hidden files in Windows
  • Hello World with Webstorm
    • seeing documentation and source code internals instantly within webstorm
  • terminal
    • go fmt
    • go run
    • go build
      • for an executable:
        • builds the file
        • reports errors, if any
        • throws away binary
    • go install
      • for an executable:
        • compiles the program (builds it)
        • names the executable the folder name holding the code
        • puts the executable in workspace / bin
          • $GOPATH / bin
  • Git & Github
    • code storage, sharing, collaboration
    • code versioning, code searching
    • programmer assessing
  • Using Github
    • windows
      • install git
    • Creating Your Own Repo
    • pushing code to github
      • from webstorm
      • from terminal
        • git status
        • git add --all
        • git commit -m “first commit”
          • first time - set remote repository (repo)

git remote add origin https://github.com/GoesToEleven/udemyTraining.git
git push -u origin master

  • git push
Section 4: Computer Fundamentals
02:03

This section is going to show you how computers work. You will learn the internal systems of a computer. You will learn about circuits and coding schemes. You will learn about binary, binary digits, and bits. You will learn how to measure bits. You will learn about numeral systems. You will learn how to use binary and hexadecimal. You will learn about format printing and format verbs. You will also learn about the history of computers.

09:56
  • CIRCUITS / SWITCHES
  • CODING SCHEMES
  • BINARY
  • 2n
  • 5 generations of computers
  • Moore's Law
12:29
  • Measuring Bits
    • Bits
    • Bytes
    • KB
    • MB
    • GB
    • TB
  • Machine Language
08:55
  • Housekeeping
  • terminal in webstorm is not unix based but command prompt (cmd.exe) based
  • changed github repo
    • update with:

go get -u github.com/goestoeleven/golangtraining

  • reading docs
    • go
    • go help get
04:07
  • understanding numeral systems
  • common numeral systems
    • decimal
    • binary
    • hexadecimal
  • reason for different numeral systems
  • fmt.Printf and formatting verbs
07:40
  • how the binary numbering system works
  • representing quantities in binary
  • hands-on exercises
07:08
  • how the hexadecimal numbering system works
  • representing quantities in hexadecimal
  • hands-on exercises
  • why we use different numbering systems
    • hex can represent larger quantities in less space
      • hex sometimes has this prefix: 0x
    • computers store binary numbers easily because they have switches that are either on or off
09:25
  • hexadecimal
    • often called hex
    • sometimes has “0x” prefix indicating it’s hex
  • Octal
    • There is a base 8 numbering system called Octal
    • often called Oct
    • Question:
      • how would you represent the number 42 in Oct?
      • Why have Oct?
  • ASCII
  • UTF
09:33
  • format printing
    • a program that prints a quantity in decimal
    • a program that prints a quantity in binary
    • a program that prints a quantity in hex
  • format verbs
    • %d
    • %b
    • %x
  • escape characters
    • \n
  • godoc.org documentation
09:46
  • format verbs
    • %#x
    • %#X
  • escape characters
    • \t
  • a program that prints a series of numbers in decimal, binary, and hex
    • loop syntax
  • a program that prints the first 200 characters of UTF-8
    • loop syntax
09:16
  • Housekeeping
    • github
      • git status
      • git add --all
      • git status
      • git commit -m “adds changes to 01 getting started folder”
      • git push
  • Review
    • How computers work
      • electricity
      • circuits / switches / transistors
      • coding schemes
        • 2n
      • binary
      • binary digits = bits
      • measuring bits
        • Bits
        • Bytes
        • KB
        • MB
        • GB
        • TB
      • Machine Language
      • 5 generations of computers
        • vacuum tubes
        • transistors
        • chips
        • cpu’s
        • ???
      • Moore's Law
    • go get
      • updating a package
        • go get -u [package name]
      • reading docs
        • go
        • go help get
    • Numeral systems
      • decimal
      • binary
      • hexadecimal
      • octal
    • Text Encoding
      • ASCII
      • UTF
    • Coding Scheme Programs
      • format printing

format verbs

    • %d
    • %b
    • %x
  • escape characters
    • \n
    • \t
  • loop
    • printed a series of numbers in decimal, binary, and hex
    • printed the first 200 characters of UTF-8
Section 5: Language Fundamentals
05:50
  • FYI
    • ardan labs training
  • preview
    • packages
    • variables
      • shorthand
      • var → zero value
    • scope
    • blank identifier
    • constants
    • memory addresses (pointers)
    • remainder
07:54
  • one folder, many files
    • package declaration in every file
    • package scope
      • something in one file is accessible to another file
    • imports have file scope
  • exported / unexported
    • aka, visible / not visible
    • we don’t say (generally speaking): public / private
    • capitalization
      • capitalize: exported, visible outside the package
      • lowercase: unexported, not visible outside the packag
05:46
  • go commands
    • go run
    • go build
    • go install
    • go clean
08:45
  • shorthand
    • can only be used inside func
  • var
    • zero value
  • type format verb
    • %T
  • not preferred methods
  • declare, assign, initialize
07:50
  • levels of scope
    • universe
    • package
    • file
    • block (curly braces)
  • FYI
    • {} - braces, curly braces, curlies, mustaches
    • [] - brackets
    • () - parentheses, parens
  • package level scope
    • for variables
    • not for imports
  • file level scope
    • imports
  • block level scope
  • keep your scope tight
10:08
  • an example of
    • block level scope
    • order mattering in block level scope
    • variable shadowing
11:14
  • closure
  • variables declared in the outer scope are accessible by statements in the inner scopes which are enclosed by the outer scope
10:03
  • reading the go language specification to reconcile what we have learned with how the language specification talks about it
  • some personal information about me, the perfection of imperfection, and our collective humanity
04:25
  • you must use everything you put in your code
    • if you declare a variable, you must use it
  • the blank identifier
    • _
    • allows you to tell the compiler you aren’t using something
  • example
    • http.Get
    • throwing away an error
09:02
  • a simple, unchanging value
  • iota’s
    • creating constants values for
      • KB
      • MB
      • GB
      • TB
07:21
  • a simple, unchanging value
  • a parallel type system
    • C / C++ has problems with a lack of strict typing
    • in Go, there is no mixing of numeric types
  • there are TYPED and UNTYPED constants
    • const hello = "Hello, World"
    • const typedHello string = "Hello, World"
  • UNTYPED constant
    • a constant value that does not yet have a fixed type
      • a “kind”
      • not yet forced to obey the strict rules that prevent combining differently typed values
  • It is this notion of an untyped constant that makes it possible for us to use constants in Go with great freedom.
  • This is useful, for instance
    • what is the type of 42?
      • int?
      • uint?
      • float64?
    • if we didn’t have UNTYPED constants (constants of a kind), then we would have to do conversion on every literal value we used
      • and that would suck
03:59
  • You are doing awesome
  • You are learning great things which, if not presented correctly, would have been way more challenging
06:41
  • memory
    • memory addresses
  • Seeing a memory address
06:19
  • pointers
    • Using memory addresses in statements
  • referencing / dereferencing
07:45
It’s all pass by value
05:46
  • remainder
  • conditional logic
    • print Odd / Even
  • loop
  • encouragement
    • building skills - awesome for
      • creating / art
      • job prospects
      • supporting yourself / your loved ones
    • Maynard
      • you got it going on, baby, you got it going on
15:03
  • ardan labs training
  • HIGH OVERVIEW
    • packages
    • variables
      • shorthand
      • var → zero value
    • scope
    • blank identifier
    • constants
    • memory addresses (pointers)
    • remainder
  • packages
    • one folder, many files
      • package declaration in every file
      • package scope
        • something in one file is accessible to another file
      • imports have file scope
    • exported / unexported
      • aka, visible / not visible
      • we don’t say (generally speaking): public / private
      • capitalization
        • capitalize: exported, visible outside the package
        • lowercase: unexported, not visible outside the package
  • go commands
    • go run
    • go build
    • go install
    • go clean
  • variables
    • shorthand
      • can only be used inside func
    • var
      • zero value
    • type format verb
      • %T
    • not preferred methods
    • declare, assign, initialize
  • scope
  • levels of scope
    • universe
    • package
    • file
    • block (curly braces)
  • FYI
    • {} - braces, curly braces, curlies, mustaches
    • [] - brackets
    • () - parentheses, parens
  • keep your scope tight
    • closure
      • variables declared in the outer scope are accessible by statements in the inner scopes which are enclosed by the outer scope
      • anonymous funcs
      • func expressions
  • Blank Identifier
    • tell the compiler you aren’t using something
      • you must use everything you put in your code
    • http.Get
      • throwing away an error
  • Constants
    • a simple, unchanging value
    • iota’s
      • creating constants values for
        • KB
        • MB
        • GB
        • TB
      • bitwise operations
    • a parallel type system
      • there are TYPED and UNTYPED constants
        • const hello = "Hello, World"
        • const typedHello string = "Hello, World”
    • UNTYPED constant
      • a constant value that does not yet have a fixed type
        • a “kind”
        • not yet forced to obey the strict rules that prevent combining differently typed values
  • Memory Addresses
    • memory
    • memory addresses
    • Seeing a memory address
  • Pointers
    • Using memory addresses in statements
    • referencing / dereferencing
    • It’s all pass by value
  • Remainder
    • remainder
    • conditional logic
      • print Odd / Even
    • loop
  • Words of Encouragement
  • You are doing awesome
  • You are learning great things which, if not presented correctly, would have been way more challenging
  • building skills - awesome for
    • creating / art
    • job prospects
    • supporting yourself / your loved ones
  • Maynard
    • you got it going on, baby, you got it going on
  • Some personal information about me, the perfection of imperfection, and our collective humanity
Section 6: Control Flow
07:04
  • sequence
  • loop / iterative
    • for loop
      • init, cond, post
    • bool (while-ish)
      • infinite
    • do-while-ish
      • break
    • continue
    • nested
  • conditionals
    • switch / case / default statements
      • no default fall-through
      • creating fall-through
      • multiple cases
      • cases can be expressions
        • evaluate to true, they run
      • type
    • if
      • the not operator
        • !
      • initialization statement
      • if / else
      • if / else if / else
      • if / else if / else if / … / else
  • Exercises
06:53
  • resources
    • https://forum.golangbridge.org/
    • Dave Cheney
  • for loop
    • documentation
      • language spec
      • effective go
    • initialization, condition, post
06:23
  • for loop
    • nested loops
07:23
  • for loop
    • condition
    • no condition
    • break
    • continue
13:01
  • documentation
    • golang spec
    • effective go
  • terminology
    • lexical elements
    • literal values
    • runes
  • rune
    • character
    • an integer value identifying a Unicode code point
    • alias for int32
      • how many bytes in 32 bits? (4 bytes → 4 * 8 = 32)
      • UTF-8 is a 4 byte coding scheme
      • with int32 (4 bytes) we have numbers for each of the code points
06:23
  • casey neistat
  • rune
  • printing UTF-8
10:40
  • using single-quotes
  • strings
    • made up of runes
07:27
  • switch / case / default statements
    • no default fall-through
    • creating fall-through
    • multiple cases
    • cases can be expressions
      • evaluate to true, they run
    • type
07:08
  • the not operator
    • !
  • initialization statement
  • if / else
  • if / else if / else
  • if / else if / else if / … / else
14:01
  • you can find the EXERCISES HERE: https://goo.gl/tGHNhA
  • exercises are presented
  • the solutions to the exercises are provided
08:41
  • Control Flow
    • sequence
    • loop / iterative
      • nested loops
      • break
      • continue
    • conditionals
      • switch / case / default statements
        • no default fall-through
        • multiple cases
        • cases can be expressions
          • evaluate to true, they run
        • type
      • if
        • the not operator
          • !
        • initialization statement
        • if / else
        • if / else if / else
        • if / else if / else if / … / else
  • resources
    • https://forum.golangbridge.org/
    • Dave Cheney blog
  • documentation
    • language spec
    • effective go
  • terminology
    • lexical elements
    • literal values
    • runes
  • rune
    • character
    • an integer value identifying a Unicode code point
    • alias for int32
      • UTF-8 is a 4 byte coding scheme
      • with int32 (4 bytes) we have numbers for each of the code points
  • strings
    • made up of runes
  • Exercise Solutions
Section 7: Functions
01:51
  • functions
    • params
      • multiple “variadic” params
    • args
      • multiple “variadic” args
    • returns
      • multiple returns
      • named returns - yuck!
    • review
      • func expressions
      • closure
    • callbacks
    • recursion
    • defer
    • anonymous self-executing functions
    • pass by value
      • reference types
    • data structures preview
      • maps
      • slices
      • structs
  • Exercises
07:48
  • func main
  • func syntax
    • func, receiver, identifier, params, returns
  • purpose of functions
    • abstract code
    • code reusability
  • parameters vs. arguments
  • declaring a func with multiple params
05:27
  • function syntax when declaring a func
  • a single return
  • a named return
  • multiple returns
06:49
a func that accepts an unlimited number of parameters
05:07
  • personal anecdote: head down, ox plowing field; doing the work
  • variadic funcs
    • my phrase: variadic parameter
    • my phrase: variadic argument
  • different ways of writing the same functionality
05:41
assigning a func to a variable
06:04
  • one scope enclosing other scopes
    • variables declared in the outer scope are accessible in inner scopes
  • closure helps us limit the scope of variables
06:49
  • passing a func as an argument
  • functional programming not something that is recommended in go, however, it is good to be aware of callbacks
  • idiomatic go: write clear, simple, readable code
05:34
a cool example of a callback
05:04
  • a func that calls itself
  • factorial example
04:20
A "defer" statement invokes a function whose execution is deferred to the moment the surrounding function returns, either because the surrounding function executed a return statement, reached the end of its function body, or because the corresponding goroutine is panicking.
06:41
in Go, everything is pass by value
05:06
  • map
  • slice
  • with reference types, you do not need to pass an address
01:39
Anonymous Self-Executing Functions
07:23
  • expressions vs statements
  • bool types
    • true, false
  • operators
    • not

!

  • or

||

  • and

&&

07:46
  • multiple returns
  • func expression
  • variadic func
  • bool & operator
06:40
  • variadic again
  • project euler
07:50

https://projecteuler.net/

10:27
  • functions
  • purpose of functions
    • abstract code
    • code reusability
      • DRY - Don’t Repeat Yourself
  • func, receiver, identifier, params, returns
  • parameters vs arguments
  • variadic funcs
    • multiple “variadic” params
    • multiple “variadic” args
  • returns
    • multiple returns
    • named returns - yuck!
  • func expressions
    • assigning a func to a variable
  • closure
    • one scope enclosing another
    • variables declared in the outer scope are accessible in inner scopes
    • closure helps us limit the scope of variables
  • callbacks
    • passing a func as an argument
  • recursion
    • factorial
  • defer
  • anonymous self-executing functions
  • pass by value
  • reference types
  • map
  • slice
  • with reference types, you do not need to pass an address
Section 8: Data Structures - Array
06:07
  • array
    • a numbered sequence of elements of a single type
    • does not change in size
    • https://golang.org/ref/spec#Array_types
  • slice
    • a list
    • A slice is a descriptor for a contiguous segment of an underlying array and provides access to a numbered sequence of elements from that array. A slice type denotes the set of all slices of arrays of its element type. The value of an uninitialized slice is nil.
    • change in size
    • have a length and a capacity
    • multi-dimensional
    • https://golang.org/ref/spec#Slice_types
  • map
    • key / value storage
    • a “dictionary”
    • A map is an unordered group of elements of one type, called the element type, indexed by a set of unique keys of another type, called the key type. The value of an uninitialized map is nil.
    • https://golang.org/ref/spec#Map_types
  • struct
    • a data structure
    • a composite type
    • allows us to collect properties together
    • https://golang.org/ref/spec#Struct_types
08:28
  • definition
    • An array is a numbered sequence of elements of a single type.
    • The number of elements is called the length and is never negative.
    • The length is part of the array's type; it must evaluate to a non-negative constant representable by a value of type int.
      • The length of an array a can be discovered using the built-in function len.
    • The elements can be addressed by integer indices 0 through len(a)-1.
    • Array types are always one-dimensional but may be composed to form multi-dimensional types.
    • not dynamic
      • does not change in size
  • a basic array
    • len
    • index access
    • assigning a value to an index position in an array
10:45
  • understanding the difference between index position and the items stored
    • if you’re storing three items in array a, those items will be at index positions 0, 1, 2
      • len(a)-1 is your last index position
        • eg, 3-1 = 2 → 2 is your last index position for your array, a, which has three items
  • using break in a loop
Section 9: Data Structures - Slice
10:04
  • definition
    • A slice is a descriptor for a contiguous segment of an underlying array and provides access to a numbered sequence of elements from that array.
    • The value of an uninitialized slice is nil.
      • it is a reference type
    • Like arrays, slices are indexable and have a length.
    • The length of a slice s can be discovered by the built-in function len;
      • Unlike arrays, slices are dynamic
        • their length may change during execution.
    • The elements can be addressed by integer indices 0 through len(s)-1.
    • A slice, once initialized, is always associated with an underlying array that holds its elements.
      • it is a reference type
    • The array underlying a slice may extend past the end of the slice.
      • Capacity is a measure of that extent:
        • it is the sum of the length of the slice and the length of the array beyond the slice;
      • The capacity of a slice a can be discovered using the built-in function cap(a).
    • make
      • A new, initialized slice value for a given element type T is made using the built-in function make, which takes a slice type and parameters specifying the length and optionally the capacity.
      • A slice created with make always allocates a new, hidden array to which the returned slice value refers.
        • make([]T, length, capacity)
        • make([]int, 50, 100)
          • same as this: new([100]int)[0:50]
    • Like arrays, slices are always one-dimensional but may be composed to construct higher-dimensional objects. (multi-dimensional slices)
  • a basic slice
09:38
  • length and capacity
    • a great example
  • index out of range errors
  • appending items to slices
  • deleting items from slices
06:33

More Slice Examples

  • multidimensional slice
  • incrementing a slice
12:43
  • shorthand
  • var
    • sets slice to zero value which is nil
  • make

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Todd McLeod, Faculty in Computer Science and Computer Information Tech

I am passionate about helping others learn and improve their lives. The courses offered under my account are courses taught by myself, along with courses I helped friends create. As for my credentials, I am tenured faculty in Computer Information Technology at Fresno City College. I have also served as adjunct faculty in Computer Science at California State University, Fresno. I began programming in 1996. I began teaching programming in 2001. My area of expertise is web programming, the Go programming language, and online education. I have taught over 560,000 students online how to build websites and use the Go programming language. Follow me on Twitter to stay current @Todd_McLeod 

Ready to start learning?
Take This Course