DEV Community

Cover image for Golang Tutorial for Beginners [FREE Course] πŸŽ‰
TechWorld with Nana
TechWorld with Nana

Posted on

Golang Tutorial for Beginners [FREE Course] πŸŽ‰

In this full Golang course you will learn about one of the youngest programming languages that is becoming more and more popular in the cloud engineering world.

You will learn everything you need to get started with Go and start using it in your projects. βœ…

What is Go? πŸ’‘

Go is a programming language, which was developed at Google in 2007 and open sourced in 2009. So it's a pretty young language.

The language is called Go. However, it's also commonly known as Golang. This is because the website was originally golang.org

Now whenever you hear about a new programming language the first question you probably have is:

  • Why do we need yet another programming language? πŸ™„
  • What is the purpose of it or how is it better or different from other already existing languages?

So before diving into the syntax, let's see what was the motivation behind creating the Go language?

Why Go was developed? How it's different from other programming languages? 🧐

Infrastructure changed

Well the infrastructure, where the applications were deployed changed a lot in the last few years:

  • Multi-core processors became common
  • and also using cloud infrastructure with hundreds or thousands of servers with multiple processors to deploy applications became pretty universal

So infrastructure became much more scalable, dynamic and had more capacity. However, most languages couldn't help in writing applications that would take advantage of these infrastructure improvements. So basically you had applications that would just execute one task at a time in order.

But with infrastructure improvements it was possible to now
write applications that would execute tasks in parallel, do multiple things at once. This way making the application faster and more user-friendly. πŸš€

Multi-Threading - Do multiple things at once

A simple example is, if you are using Google Drive you may be uploading or downloading files and folders, but you can keep navigating back and forth in the UI. So downloading, uploading and navigating the UI all happen in parallel.
So the application allows you to do multiple things at once without affecting any other task:
Google Drive - work in parallel

And this is a concept of multi-threading. So each thread is basically processing one task and you can have many of them running in parallel and this makes applications fast but may also cause some issues. πŸ‘€

Challenges

For example on Google Docs, many users can work on the same document at the same time. So when you have two users changing and adding stuff at the same time to the same document, this should work smoothly without one user overriding all the changes that another user is making.

Another example where such issues may happen, when things are processed in parallel is a booking system for buying tickets or booking a hotel etc. Let's say again two users are trying to book the last remaining ticket at the same time. Of course this should work in a way that no double booking happens.

And this concept is called concurrency and needs to be handled by developers in code. So they must write code that prevents any conflicts between the tasks, when multiple tasks are running in parallel and updating the same data.

Concurrency

Language Concurrency Support

Many languages do have features for implementing such applications, however the code can get pretty complex and
handling and preventing the concurrency issues can be pretty hard. And with complexity there is always a higher risk of human errors and that's where the main purpose and difference of Go comes into the picture.

So Go was designed exactly for that purpose to make writing multi-threaded concurrent applications that take advantage of the new performance infrastructure much easier.

Multi-Core Concurrency Support

We will learn about this in more detail at the end of the course, when we use goroutines:
Goroutine vs OS Threads

Main Use Case of Go

So logically enough the main use case of Go or what it's best used for is writing applications that need to be very performant and will run on the modern scaled and distributed infrastructure with hundreds and thousands of servers typically on a cloud platform.

Go is used on the server side or the backend of the applications and these types of applications can range from microservices and web applications to database services.
And so in fact, many cloud technologies or technologies that run on modern cloud environments are actually written in Go, like Docker 🐳, Hashicorp Vault, Kubernetes, CockroachDB and so on.

Characterstics of Go Language

Compiled Language

Go is a compiled language and it compiles actually very quickly into a single binary. You can deploy and run it on different platforms in a consistent way, so no matter which operating system or which environment you're using you can take that same binary and basically use it across different platforms.

Combine Ease of Programming with Efficiency and Safety

For developing Go, they wanted to take the simplicity of syntax of a more high-level language, like Python and the speed and efficiency of a lower level language like C++.
So you will see the combination of these things in Go.
Go combines Python and C++

Language features left out on purpose for simplicity πŸ’‘ The goal was that the code should be easy to maintain over time.

  • The simple syntax makes your code very maintainable, easy to read and extend.
  • Go applications can be built very fast, they are also very fast in startup and also when they're running.
  • Go is very resource efficient, which means it uses few resources or it requires fewer resources like CPU and RAM to run.

Considering all these benefits of simplicity and speed and so on, Go is also becoming more and more popular for writing simple automation applications and CLI applications for DevOps and SRE tasks as well.


So now that we know why Go was created and what differentiates it from other languages πŸ‘ , let's jump right into learning the core concepts and syntax of Go.

Learn Syntax and Concepts while writing a simple application πŸ‘©β€πŸ’»

In the tutorial, we're going to write a very simple ticket booking application to learn the basics of Go. So instead of learning the concepts and syntax of Go with isolated examples, you will learn them while building an actual application throughout the tutorial. 😎

But for the demo part, let's continue with the video, so you can follow along more easily: πŸ€“

β–¬β–¬β–¬β–¬β–¬β–¬ COURSE OVERVIEW πŸ“š β–¬β–¬β–¬β–¬β–¬β–¬

πŸ’Ž Part 01: Introduction to Go

  • What is Go? Why Go?
  • How it's different from other programming languages?
  • Characteristics of Go and Go Use Cases

πŸ’Ž Part 02: Local Setup

  • Install Go & Editor
  • Write our First Program & Structure of a Go File

πŸ’Ž Part 03: Go Syntax & Concepts

  • Variables & Constants in Go
  • Formatted Output - printf
  • Data Types in Go
  • Getting User Input
  • What is a Pointer?
  • Arrays & Slices
  • Loops in Go
  • Conditionals (if / else) and Boolean Data Type
  • Validate User Input
  • Switch Statement
  • Encapsulate Logic with Functions
  • Organize Code with Go Packages
  • Scope Rules in Go
  • Maps
  • Structs

πŸ’Ž Part 04: Concurrency in Go

  • Goroutines

Hope you will learn a lot in this beginner tutorial!


Like, share and follow me 😍 for more content:

Top comments (3)

Collapse
 
vajracool profile image
VajraCool

As always you are just awesome, I wonder how many languages (programming) you know and how you do you remember the syntaxes, differences, etc..? How do you get time and differentiate with new languages?

Collapse
 
phyberapex profile image
PhyberApex

Another great post of my favorite dev teacher, Nana!

~Cheers

Collapse
 
aioriaxp profile image
RoArDev

Congratulations, this is very well explained and great content. Thank you