Other Parts of This Series:
DevOps Basic Golang Programming (Photo Credit: Unsplash)
Story:
The roadmap defined was done, and it’s time to start learning accordingly. The first step was learning a programming language. Though Rasel was working on C# (.NET), he decided to learn a new lightweight and faster language and picked Golang. Because Golang is lightweight, faster, and cloud-native. Many DevOps tools, like Docker and Kubernetes, are built using Golang.
As Rasel knows the programming fundamentals, it was easy to cross-check and learn it in the earliest time.
Programming Fundamentals:
In every programming language, basically the following fundamental things are the backbone:
- Part 1: Let’s Feel Programming Fundamentals - Part 1
- Part 2: Let’s Feel Programming Fundamentals - Part 2 (Variable, Operator)
- Part 3: Let’s Feel Programming Fundamentals - Part 3 (Condition, Loop)
- Part 4: Let’s Feel Programming Fundamentals - Part 4 (Function, Pointer, Scope)
- Part 5: Let’s Feel Programming Fundamentals - Part 5 (Procedural, Functional, OOP Style)
- Part 6: Let’s Feel Programming Fundamentals - Part 6 (Data Structure)
- Part 7: Let’s Feel Programming Fundamentals - Part 7 (Algorithm)
- Part 8: Let’s Feel Programming Fundamentals - Part 8 (Threads, Async-await, Concurrency, Parallel)
How to these Concepts Works in Golang:
Data Types, Variables, and Constants
- Data Types: Go has basic types like int, string, bool, and float64.
- Variables: Declared using var or := (short-hand declaration).
- Constants: Declared using const, and their values cannot change.
Operators
- Arithmetic Operators: +, -, *, /, %
- Relational Operators: ==, !=, <, >, <=, >=
- Logical Operators: &&, ||, !
- Assignment Operators: =, +=, -=, *=, /=
Condition (if-else & switch)
- Used for decision-making.
| |
Loop (for loop)
- Go only has for loops (it replaces while and do-while).
Function
- Functions help organize reusable code.
Memory Allocation and Pointers
- Pointers store memory addresses.
- new() allocates memory dynamically.
Variable Lifetime and Scope
- Global variables exist throughout the program.
- Local variables exist only inside functions.
Object-Oriented Concepts (Structs & Methods)
- Structs are like objects in Go.
- interfaces are the declarations of function prototypes that can implemented.
- Methods are functions attached to structs.
| |
Data Structures
- Array: Fixed size
- Slice: Dynamic array
- Map: Key-value pairs
| |
Algorithm (Sorting Example)
- Implementing Bubble Sort algorithm.
| |
Concurrency (Goroutines & Channels)
- Goroutines allow parallel execution.
- Channels enable safe communication.
| |
Besides all of this, error handling, testing, generics are also advanced topics should be learned.
Summary:
Go (Golang) is a simple and efficient programming language with strong support for concurrency and performance. It has basic data types like int, string, bool, and float64, and allows you to store values in variables or constants (which don’t change). You can perform calculations and comparisons using operators such as +, -, ==, and &&. To make decisions, Go provides conditional statements like if, else, and switch, while repetitive tasks can be handled using loops, mainly the for loop.
Functions help break code into reusable blocks, and Go uses structs, methods and interfaces instead of traditional classes for object-oriented programming. Go also provides pointers to store memory addresses, and variables have lifetime and scope, meaning they exist for a certain time and in a certain part of the program. Data in Go can be organized using data structures like arrays, slices, maps, and structs, while algorithms define step-by-step solutions to problems.
A standout feature of Go is concurrency, allowing multiple tasks to run at the same time using goroutines and channels. This makes Go ideal for building fast, scalable applications. Overall, Go is designed to be simple, fast, and highly efficient, making it great for web development, cloud computing, and system programming.