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.
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.
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/localtar-C /usr/local -xzf go1.24.1.linux-amd64.tar.gz
# Add the bin path to access go commandexport PATH=$PATH:/usr/local/go/bin
# Test
go version
Let’s write the hello, world program. Create a file with name hello.go and write the following code.
Run the following command in the terminal to run this program.
go run hello.go
hello, world
Explanation of the hello, world Program
You can package your code by any name you want to arrange your code logically. But, package main is the special package that should contain main() function. We’ll talk about package stuff in future if it looks confusing to you. For now, just add package main at the top of the file. We we write something else as name of the package than main, you’ll know the meaning of it.
import is used to import the library or package. Here, we are importing fmt standard library to access the Println() function.
Execution of the program starts from main() function. func keyword is used to define function.
Println() function is used to print text in the terminal. Println() is part of fmt. Remember that P is capital in Println() 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.
varxint
As 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.
varxint=42
If 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.
varx=42
Even further, replace boring= with interesting:= operator and you don’t have to write var keyword.
x:=42
And 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.
boolstringintint8int16int32int64uintuint8uint16uint32uint64uintptrbyte// alias for uint8rune// alias for int32// represents a Unicode code pointfloat32float64complex64complex128nil
You 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.
In Go, variables can be reassigned and are mutable by default. Unlike current tend, Go doesn’t enforce immutability by default.
age:=32age=42fmt.Println(age)
Output is:
42
In 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 _:
_=12result:=12+10_=result// If you're not going to use result
String 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.
packagemainimport"fmt"funcmain(){name:="Bruce"age:=32fmt.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.