Welcome to The Go Language Lecture Series.
In this third volume, we delve into essential topics that will enhance your understanding of Go. We will review critical topics from previous volumes and quickly get into new material. Here's a list of the areas we will be covering. It's over 4 hours of essential Go exercises for practicing, learning, and reviewing:
Welcome to The Go Language Lecture Series.
In this third volume, we delve into essential topics that will enhance your understanding of Go. We will review critical topics from previous volumes and quickly get into new material. Here's a list of the areas we will be covering. It's over 4 hours of essential Go exercises for practicing, learning, and reviewing:
Blank Identifier: A reintroduction to this powerful tool and how to use it.
Datatype Inference and Zeroed Values: Understand how Go infers types and initializes variables.
Creating Custom Data Types: Learn how to define your own structures and types.
Type Aliases in Go: Simplify complex type names.
For Range Loop: A deeper exploration of this versatile construct.
Importing useful packages from GitHub.
Struct Datatype: Dive into structs with practical exercises.
Interfaces Applied to Structs: Unleash the power of interfaces.
Map Data Types: Master maps for efficient data storage.
Expect quick drills that target specific concepts, as well as repetitive tips to cement important ideas. Whether you spend four hours or several weeks, this volume is a valuable resource. Use it for reviewing during your own projects, we will keep it updated and add more details over time.
Let’s embark on this learning journey together.
Hello and thanks for your interest on the exercises that follow. We will begin with a reintroduction to the blank identifier, moving next to datatypes, inference, and zeroed values. Then, we will see how to create our own datatypes, as well as how to create type aliases in Go. Next, we will reintroduce the range loop, and move quickly to struct datatypes where we will do multiple exercises to illustrate specific concepts that we must know. After structs we will work with Interfaces as applied to structs. And later we will add map datatypes to the mix. Then finally, we will do several exercises with interface parameters as applied to strings, numbers, maps, slices, and variadic functions. This volume is packed with simple, quick exercises, targeting specific concepts we must know and should review periodically. Let's begin, my friend. I'll see you on the next session. Thank you.
Reintroducing the blank identifier in Go.
A general review of datatypes, type inference, and default values in Go.
Introduction to customized data types in the Go language.
The difference between own-type and type-alias. How to display the type of variable to screen in Go.
For range loop review and additional information.
Introduction to structs in the Go language. What are structs, how to declare a basic struct, introduction to fields, datatypes, and a function receiver example.
How to declare a variable of type struct and add values to it.
How to include values at the time of a struct variable declaration. How to skip values or reorder values at declaration.
Go accepts leading commas in literal value declarations. When to use them and why.
How to create an anonymous struct to be used in a single variable declaration.
Quick review of struct variable declarations. Also, how to declare a struct using function new versus asterisk.
How to address field values in a struct of type array or slice. Syntax and looping ideas.
How to create a function to edit structs in Go. Introducing the receiver parameter, which replaces the "this" keyword from other languages.
How to create a Go method without using a receiver. What is early binding versus late binding.
This exercise demonstrates that in Go, receiver parameters can accept variables of a designated type, or pointers to variables of the same type. This flexibility is not available on regular function parameters.
This exercise demonstrates how function receiver parameters only accept types that reside locally. It illustrates the concept without unnecessary jargon.
Go does not support function overloading in its traditional sense. We can however, emulate overloading by using different receivers. Function overloading is when we use the same name for functions that accomplish different things.
Go does not support inheritance or sub classing. Instead, it promotes what is called implicit delegation. The term delegation, in generally, refers to when one entity, such as a struct, for example, passes something to another entity, like delegating its fields to another struct. Trough delegation we can, in our example here, use the fields from struct Person in Student instead of rewriting similar fields.
Delegating structs also delegates their methods. Delegated methods can be overridden.
How to override delegated fields in a Go struct. Also assigning fewer fields upon variable declaration.
How to loop over the fields in a Go struct. How to import a package from Github.
Practicing exercise: How to declare a range loop to iterate over a Go struct.
Solution for the previous exercise: how to declare a range loop to iterate over a Go struct.
How to include a function as a value in a Go struct field.
0:00… How to see if a field is "empty".
2:02… How to compare two structs.
3:08… How to see if a struct has own values.
4:49… How use "reflect" to compare structs at runtime.
Congratulations for finishing the structs exercises or even returning to review these concepts periodically. We could go on and on with structs, but we also need to stop somewhere and visit other data structures, which will help us better understand the ones we already know so far. Knowing several data structures permit us to use structs in more complex outcomes. Before we go, let's review the commons ways for declaring a variable of type struct
A metaphorical view of what an interface is in the Go language as well as the requirements for membership.
What is the benefit of subscribing a given interface?
How to declare an interface, a function router method, and and to put it to use. The last downloadable file contains the complete code.
How do we add a return value to interface member functions in the Go language? The function signature of member functions must match the function signature listed in the interface.
How to add arguments to interface member functions. How to accept different datatypes when calling the same function. The empty interface quick introduction.
How to declare a slice of type interface to gather all members and loop their content to screen.
Congratulations and where we go from here.
Introduction to maps in Go. The difference between a struct and a map. When to use a map, a slice, or a struct.
How to declare a map container by using the make function. How to assign values to a map.
How to declare a map container with literal values. Reviewing leading commas in Go.
How to add new items to a map. How to edit or delete existing items from a map.
How to use the blank identifier to ignore a variable in a tuple assignment. How to temporarily ignore an imported package. How to declare a variable without having to use it in the executable code.
Ho to verify if an item exists in a Go map. The comma ok pattern.
How to loop over a map using a for range loop. This creates an unsorted output. See next session for a way to sort the output.
How to sort the keys in a map for displaying purposes. The sort package, the Strings and Ints functions. Creating a slice of map keys.
Hoe to change the name of a key in a Go map. Also introduction to map length and map capacity.
Introduction to interfaces as parameters. The empty interface.
Ho to assert an argument from an interface parameter to prevent a datatype error. The comma ok pattern.
How to display the asserted argument from an interface parameter, or an alternative message if the argument is invalid.
How to fork your function code based on the datatype being submitted. Introducing the type keyword and switch mechanism.
How to check for a datatype in an interface parameter from multiple possibilities, using the switch mechanism.
How to pass a map datatype to a function via an interface parameter and how to describe the map in a switch construct.
How to submit an indefinite number of variables to a function even if those variables are of different datatypes. Introducing variadic function parameters for single types or interfaced types.
How to loop over variadic arguments to display values. Why these values cannot be used in calculations because they have not been asserted.
How to assert arguments while traversing a variadic parameter using a range loop.
How to pass a slice as an argument to a variadic parameter. How to assert a slice type.
Congratulations, my friend. Please revisit often.
OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.
Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.
Find this site helpful? Tell a friend about us.
We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.
Your purchases help us maintain our catalog and keep our servers humming without ads.
Thank you for supporting OpenCourser.