Catchy Advice, Boring Advice
On the other day, I was reading a post on a social network where a person who went to an interview for the position of (junior) developer asked a question at the end of it: how one can become a senior developer. He was very impressed by the answer of the interviewer. The answer was,
Being a senior developer is about how to handle people, how to teach them, how to guide and mentor them. You’ll have a group of juniors under you with different mindsets. You need to know their mindset and behave accordingly…
…blah blah blah. This answer may look good. You may be impressed by the answer. But wait! Does that mean if you are good at people management and can mentor them, then you’re a senior developer? I mean, where is the point of being very good or an expert at development to become a senior developer? Where is the point where you need to be good at estimation, implementation planning, knowing risks in the technical decisions, business values, etc.? Aren’t those needed to become a senior developer, or is just people management and mentoring enough?
On the pretense of saying something that looks catchy, they’re ignoring the base. Or are they assuming the base when giving a shining opinion to impress people? Like, being good at development is the base to become a senior developer, isn’t it?
I remember watching an interview where the interviewer mentioned that focus was the reason for Bill Gate’s success. Then someone suggested that curiosity was the reason why he was successful. These are absolutely correct reasons to be successful. But, does that means if I sharpen my focus on something for half an hour every day, that I’ll become successful? No. One must need to work hard as the base. Focusing on one thing is very important, but hard work is essential. Why are people not talking about hard work nowadays? Is it because talking about hard work is boring? I don’t know.
---
Welcome to Go
Go or Golang is a static, inferred, structural programming language created by Robert Griesemer, Rob Pike, and Ken Thompson initially at Google. It has built-in support for concurrency, testing, and has rich standard library.
Go is extremely easy to dive into. There are a minimal number of fundamental language concepts and the syntax is clean and designed to be clear and unambiguous. - Dave Astels.
Install Go
Let’s first install the Golang. You can find the release binary from the official download page and instructions in the official installation guide.
As I’m using GNU/Linux system, I need to follow these steps. The
steps for the GNU/Linux are written so clearly that I follow these steps
even I want to install something else from given .tar.gz file.
# unzip the .tar.gz file at /usr/local
tar -C /usr/local -xzf go1.24.1.linux-amd64.tar.gz# Add the bin path to access go command
export PATH=$PATH:/usr/local/go/bin# Test
go versionLet’s write the hello, world program. Create a file with name hello.go and write the following code.
package main
import "fmt"
func main() {
fmt.Println("hello, world")
}Run the following command in the terminal to run this program.
go run hello.go
hello, worldExplanation of the hello, world Program
- You can package your code by any name you want to arrange your code logically. But,
package mainis the special package that should containmain()function. We’ll talk about package stuff in future if it looks confusing to you. For now, just addpackage mainat the top of the file. We we write something else as name of the package thanmain, you’ll know the meaning of it. importis used to import the library or package. Here, we are importingfmtstandard library to access thePrintln()function.- Execution of the program starts from
main()function.funckeyword is used to define function. Println()function is used to print text in the terminal.Println()is part offmt. Remember thatPis capital inPrintln()function.
Variables
There are multiple ways to define variables and assign values to them. As Go is static programming language, type is bound to the variable than the value. What value a variable can accept is depends on type it bound to.
To define a variable following syntax is used. var keyword, followed by name of the variable, and finally the type of the variable.
var x intAs the type of x is int, it can only accept valid integer values. Assigning floating number of string results in error.
Boring = or assignment operator is used to assign value to the variable.
var x int = 42If you are assigning the value to the variable at the time of defining it, you can drop the type from the syntax as Go will inter the type based on initial value.
var x = 42Even further, replace boring = with interesting := operator and you don’t have to write var keyword.
x := 42And now you know couple of ways to define variable in Go. Use the syntax that make more sense to you in terms of program context and usage.
Go is rich in types. Following are some the basic data types Go has supports for.
bool
string
int int8 int16 int32 int64
uint uint8 uint16 uint32 uint64 uintptr
byte // alias for uint8
rune // alias for int32
// represents a Unicode code point
float32 float64
complex64 complex128
nilYou don’t have to remember all these types! You’ll get to know and use these types as you get more experience with Go.
Here is an example program that demonstrate the usage of some of the types from above list.
package main
import "fmt"
func main() {
var name string = "Peter" // String
var age int = 32 // Integer
var height float64 = 190.47 // Float64
var adult bool = true // Boolean
var address *string = nil // Nil pointer
fmt.Println(name, age, height, adult, address)
}Output is:
Peter 32 190.47 true <nil>In Go, variables can be reassigned and are mutable by default. Unlike current tend, Go doesn’t enforce immutability by default.
age := 32
age = 42
fmt.Println(age)Output is:
42In Go, if you declare a variable but don’t use it, the compiler will
give an error. To ignore values and fix the compiler error, use the
blank identifier _:
_ = 12
result := 12 + 10
_ = result // If you're not going to use resultString Interpolation and Concatenation
Go uses the fmt package for string formatting and the + operator for concatenation. Go use Printf() function with format specifier to do the string interpolation.
package main
import "fmt"
func main() {
name := "Bruce"
age := 32
fmt.Printf("I am %s and %d years old\n", name, age)
fmt.Println("But my real name is " + "Batman ðĶ")
}Output is:
I am Bruce and 32 years old
But my real name is Batman ðĶFinally, following are the list of popular projects created in Golang.
Acknowledgement: This article is heavily inspired by content from RunElixir.com.
---