Reviewing Programming Fundamentals with Go: The Basics
In a few weeks, I will start the excruciating quest on the search for the very overrated treasure that we all call The Master's Degree in Computer Science, and I feel like some reviewing is in order. Especially with COVID still orbiting for the foreseeable future, there hasn't been a better time to review some fundamentals for my benefit and everyone else's. However, I have seen enough programming tutorials and read a good amount of CS books to know what I find enjoyable. The fundamentals of computer science are commonly done on languages that I don't use on an everyday basis nor I have enough interest to dive into. With all of this in mind, I am now starting a new series of posts reviewing what we developers seem to feel are the base of every successful career on Computer Science but with the use of the Go Programming Language.
In any case, let's start with some basic knowledge. and work our way down.
In math, we use variables as placeholders of specific values. For example:
x + 2 = 3
On the equation above, x is a placeholder for the value 1. In programming, we also make use of variables as placeholders for data. For example:
var x = 1
The declaration above creates a new placeholder X, and we set the value 1 to it. Writing down a new variable on code is called a variable declaration. One can make a new variable in the following ways:
The most common way to declare a new variable on Go. Here the type is inferred from the value assigned to the variable:
var a = "one"
Declaring two variables at once:
var b, c = "two"
Declaring two variables at once, with different values:
var d, e = 3, 4
Declaring a variable and its type:
var f int = 5
This the same as
var g = 3:
g := 3