Programming with Go

Let’s start programming with GoLang, if you’re not aware of Go then you can refer my previous posts about Introduction to Go and Setting up your machine for Go. If you haven’t finalized an IDE for Go Programming then you should checkout the post about IDEs and Text Editor plugins.

Go is a C like programming language, which resembles C type programming methods in many times.

You can run a Go code by executing the command go run /path/filename.go

So let’s start with Hello World

Package `fmt` implements formatted I/O with functions analogous to C’s printf and scanf.

Sum of Two Variables

In Go we can initialize a variable in two methods either by specifying the `variable type` or simply as `short variables`. In case of short variable declaration the variable type is selected depends on the assigning value.

Let’s move ahead with an advanced code to solve few arithmetic operations.

Here I’m building a calculator using Go.

You might get slightly confused with the function, but don’t worry I will explain about it in my next posts. Here I used return type float32, is to mention return is a 32bit float value (you will be able to use float64 also), and %f is used for printing a float value like we use in C. %.2f is used to limit the decimal points. You can simply try out different methods.

Currently we haven’t defined any methods to handle the invalid operators in our code. So I’m making it more functional by defining one status flag on the returning statement to handle invalid operators.

Happy Programming :)