Monthly Archives: January 2018

Control Flow in Golang

Control Flow in Golang

control flow in golang


As we have covered Golang ‘language fundamentals’ in our Chapter-3,  let’s explore ‘Control Flow’ and ‘Functions’ in this chapter.

The control flow statements are used to break the flow of execution by branching, looping, decision making statements by enabling the program to execute code based on the conditions. All programmers must know the control flows like if-else, switch case, for loop, break, continue, return.

  • if/else

  • if/else if/else

  • if/else if/else if/…../else

The if statement is similar to other programming languages. If the statement is expecting some condition and based on the condition it will execute the code.



Note:  use else/else if just after closing of if statement’s closing bracket “}“ otherwise you will get compile time error.

pasted image 0 (6)

Here ,you can see how the fmt.Println() is implemented in “fmt” package. func Println(a …interface{})(n int,err error)

So the Println function can take any number of arguments of any type. We can also pass slice of ints for the variadic function.


For loop

Golang has only one loop which for loop. Like other programming languages, it doesn’t have while and do while loop. But we can use for loop as while loop.

Golang coding


Switch case

Most programming languages have switch case to avoid complex if-else-if statements.

  • we can compare only values of same types

  • we can set optional default statement if condition fails

  • we can use expression if need to compare condition based on value to use


switch case


“fallthrough” is optional in switch case. This keyword is used in case statement and when it is encountered, it will go to next case even if next case is failing condition. So it is optional in this switch case.

We can specify multiple values in case statement. Also we can return a value based on switch cases.



Normally we switch on value of a variable but Golang allows you to switch on type also.





Functions are no. of statement that together performs a task and make execution flow more reliable so that we can reuse the code whenever needed.

The execution of Go program starts from the main function itself func main(){    } . A function takes one or more parameters and return one or more outputs. Like other programming languages, go explicitly needs to return values.

The Syntax is




Function starts with keyword func and its name. The parameters need to define like var_name  var_type. After this we need to write return type if function is going to return. Writing of function can be difficult so better idea is to break into manageable code, rather that going for full implementation.


Function as expression

We can pass function to an expression and call that function by using expression/variable name. This is the only way to have one function inside another.

If you see the type of expression then it will be a func()



No identifier is there and function is anonymous(nameless)


We can create a function inside functions i.e. nesting of functions.

For this purpose, Go supports anonymous function i.e. function without a name which will become local to the function.



Closure helps us limit the scope of variables used by multiple functions. Without closure,for two or more funcs to have access to same variable, that variable would need to be in package scope.


Passing a function as an argument is called callback in golang. Here, we can pass function as an argument.



Here we are passing func call( ) as an argument to the func show( )


Recursion is a function which calls itself. It is like two mirrors facing to each other.


  • Recursion will create a stack of function calls every time.

  • Sometimes recursion is the best solutions.

  • Closure and Recursion are the powerful technique of programming which forms functional programming and most of the people find recursion difficult to understand that the control flow statements.


Go has a special statement defer which schedules a function call to execute before function completes.

Defer is used when resources need to be freed away i.e. same like finally block in java which is used to put the resource releasing logic.

For ex. Whenever we open the file we need to make sure to close it or while connecting to the database after completion of the task we need to close the connection.




  • It keeps our Close() near to the Open() and it’s easy to understand     


  • deferred func will always run even if runtime panic err occurs



Pass By value

Strictly speaking, there is only one way to pass parameters in Go is Pass By Value. Whenever a variable is passed as a parameter, a copy of that variable is created and passed to the function and this copy will be at a different memory location.

In case, variable is passed as a pointer argument then again new copy of parameter is created and that will point to the same address.



Note that even though func changeIt() changes the name to ‘Rafel’, it does not affect the variable name in main function. This happens because function modifies copy of variable not the original one.

But the func change() is modifying the value because &per and per are two different pointers pointing to same struct which is stored at the same memory address.

Anonymous Function

Anonymous functions are the self-executing functions which are nameless i.e.they do not have name. Only through anonymous function we can do nesting of functions i.e. one function inside another.



Variadic Function

This one is a special form of function which can take any arguments. It is like varargs in Java. We can pass any number of parameters to the variadic function of same type. To make function variadic you just need to put three dots … before the arguments type. It will allow you to pass any number of arguments to the function.

varidiac function


Here, you can see how the fmt.Println() is implemented in “fmt” package. func Println(a …interface{})(n int,err error)

So the Println function can take any number of arguments of any type. We can also pass slice of ints for the variadic function.



Well, we are now all set with major control flows and functions for Golang. In our next chapter, we will explore Golang Data Structures. Make sure you check it out!  

Reactive Programming -Future of Programming

Reactive Programming -Future of Programming



Developing great apps nowadays require many things like handle User Interaction, handle network related stuff, manage data as well as present them. For that Developer has to write lots of concurrent as well as asynchronous code.

Nowadays if you take a look on the internet as a developer than somewhere you have read the term Reactive programming. You might wonder what’s this term actually means and why it takes storm between the developers. Many developers say it is the Next big thing in the programming world. Maybe as a developer you are still unaware what the world is talking about so you are curious to know on this and make yourself to be the part of this incredible world of programming.

So if you are bibelot about this topic and search on the internet than here is what type of definition you will find:

“Reactive programming is an asynchronous programming paradigm concerned with data streams and the propagation of change.”




At the initial stage, it is very hard to understand what it really meant. This is the reason why I am writing this blog. So that everyone can able to know how reactive programming will help you in coding with an easy and understandable way.

I will try to explain to you in a very easy and fun manner that how it will attract you to use in your real-world apps and projects. I am sure you will definitely understand this by the fun conversation between me and my friend Taral

reactive programming example
reactive programming


As an application developer, we always need to make our app smooth as butter. For that we have to handle many things like below :

  • Handle multiple URL responses at the same time
  • Multiple UI changes
  • Manage Database
  • Handling all the other frameworks we are using
  • Many more things


To tackle all these we often use many frameworks also use some logic by putting UI related changes to the Main thread and other time-consuming stuff in a background thread. We’ll try to keep our main thread free. Writing code that truly runs in parallel, however, is rather complex, especially when different bits of code need to work with the same pieces of data. It’s hard to argue about which piece of code updates the data first, or which code read the latest value.


So for an alternative of all these, here comes the Reactive Programming to give you power and fight for your code.


Reactive Programming ~= Asynchronous programming



Basically, Rx is asynchronous programming that handles your code to react to the data in observable sequences. It defines the structural programming in which one component emits the data and other components which are registered to receive will propagate those changes.

There are three building blocks of Rx

1) Observables — Component that Emits the Data

2) Observers — Components that subscribes to observable to get changes

3) Schedulers — schedule the different pieces of data coming from observable

For example :

X = Y + Z

X is an observer here because it subscribes to the result of y+z

Y & Z are observables here because it omits the changes.





This Blog Explains you Reactive Programming in the most simple way. If you want to know more about Reactive Programming you can visit our blog Reactive Programming in SWIFT


About RemotePanda

RemotePanda is a personalized platform for companies to hire remote talent and get the quality work delivered from the city Pune. The resources in our talent pool are our close network connections. While connecting them with you, we make sure to manage the quality, growth, legalities, and the delivery of their work. The idea is to make remote work successful for you. Get in touch with us to learn why RemotePanda is the best fit solution for your business requirements.

Golang Language Fundamentals

Golang Language Fundamentals

golang language fundamentals


As we have already covered the basics of Golang in our Chapter-1 and how to create your first Go Project in Chapter-2,  let’s dive deeper into language fundamentals.


  • Organize the code just like we organize our files into computers
  • Folder name should be the same as the package name
  • One package many files (If something is in lowercase, it will not be exported outside the package)
  • Package scope: something in one file is accessible to another file
  • Imports have file scope
  • Capitalization:
  • Uppercase: exported, visible outside the package
  • Lowercase: unexported, not visible outside the package


Data Types

Data types are used for declaring variables or functions of different types. The variable type determines how much memory space occupies in storage and bit pattern stored is interpreted.

  • Boolean Types – These are predefined constants : (a)true (b) false
  • Numeric Types – Represents (a) integer types  (b) Floating point values
  • String type – Predeclared string type is the string having set of characters
  • Derived types – (a)Pointer types (b)Array types (c) Structure types (d)Union types (e)Function types (f) Slice types (g)interface types  (h) Map types

Integer Types











Unsigned 8-bit integers (0 to 255)

Unsigned 8-bit integers (0 to 65535)

Unsigned 32-bit integers (0 to 4294967295)

Unsigned 64-bit integers (0 to 18446744073709551615)

Signed 8-bit integers (-128 to 127)

Signed 16 bit integers (-32768 to 32767)

Signed 32 bit integers (-2147483648 to 2147483647)

(-9223372036854775808 to 9223372036854775807)


Floating type








IEEE-754 32-bit floating point numbers

IEEE-754 64-bit floating point numbers

complex numbers with float32 real and imaginary parts

complex numbers with float64 real and imaginary parts

Other Numeric types








same as uint8

same as int32

32 or 64 bits

same as uint

an unsigned integer to store uninterpreted bits of pointer value


There are two primary ways of declaring variables –

shorthand method→  can only be used inside func (mostly used)

var →  used to set things to zero values

Here no value is initialized and later assigned to variables. Go automatically assigned default values to it

For Booleans→  false   for integer→ 0   for float→ 0.0    for strings→ ””

For pointers, maps, slices, functions, interfaces, channels→  nil


%v →  value in default format ,when printing structs use +%v

%#v  → value representation

%T  → data type of value


%t  → the word true or false


%b  → binary representation of int value

%d →decimal representation of int value

%c → character representation

%o → octal representation of int value

%x  →Hex representation with small letters a-f

%X → Hex representation with capital letters A-F


%s  → String or slice

%q →double quoted string safely escaped with Go-syntax


%p →Hex representation with leading 0x

For the formats go to Go Documentation


Golang project explorer

Demo Screenshot

Find below the example of how packages can be created and used

Golang Package


Here, if you try to access the stringutil.yourname variable it will give an error like below – (because your name variable should start with a capital letter)

Golang documentation



Scope means where the variable will be accessible. We declare variables, functions, identifiers in the program.

Levels of Scope

universe →  package → file → block (curly braces)

{} – braces    []- brackets    ()-parentheses

Package Level Scope→   for variables; not for imports

The scope of x is for the whole package; means it is accessible throughout the program. But if we declare any variable inside the function then we can’t use it in another function.

In below examples, capitalized variables having package scope can be imported to another package

Golang Demo


Here name.go and your.go files are present in “scope/scopes/myPack”” package. Importing of the package is needed to use variables/functions from another package.

Closure {  }  limits the scope of the variable outside the functions

Access scope matters a lot. The imports pFile Level Scope → It is only for packages

Block Level Scope →  access scope is only within the function itself

Remember, keep your scope tight

Blank Identifier

Keep in mind that you must use everything that you put in your code

If you declare a variable, you must have to use it the otherwise compile-time error will show. The blank identifier tells the compiler that you are not using something and it is declared with ‘_’ symbol.



Error: b declared but not used




In Golang “const” keyword is used for declaring constants. These constants value is like final that no one is allowed to change and will remain the same whenever we are using it. It is an unchanging value.



“Iota” is used in const declaration for simplifying declarations of incrementing variables. The value of iota is reset to 0 and increments after each line.

Memory Addresses

For every variable value, we stored has a memory address. To know the stored memory address of variable we use ‘&’ (ampersand) operator.  




Like C Language, Go also supports pointer. Pointer is used to hold the memory address of a value. It is represented by using “*” (asterisk) just like the C language.

For example, *int is pronounced as pointer to int value.


var p *int

The & operator generates a pointer to its operands.





We can pass memory address i.e. reference instead of a bunch of values and we still can change the values. So we don’t need to pass values, instead, we can pass addresses.

Problem without Pointer                                                                               




We use “%” for getting remainder.



This is all about language fundamentals. Check out chapter-4 where we will talk about ‘Control Flow’ and ‘Functions’.

Best Android Libraries for Developers

Best Android Libraries for Developers

best android libraries for developers


All Android Apps tend to have very similar basic functionalities. They all need to look good, store some data locally, load images and communicate with a server. There is no need for each developer to reinvent the wheel every time they want to develop a new app. There are some very good Android libraries out there to help you with these basic functionalities. Let’s take a look at some of the very essential libraries —


HTTP Client-

HTTP Client


In almost every app you build, you will need to connect with an API server to send and receive data. While Android provides a way to connect with the API server, it is quite basic and you will need to do a lot of the heavy lifting yourself and write repetitive code. Retrofit and Volley are two of the most popular libraries used in Android for handling HTTP. Having explored both of them, my team and I prefer Retrofit. It is fairly easy to set up, with enough configurations that a basic app will need and also helps you keep your code clean.


Database Management-

Database Management


You generally need to store some data locally in your app. For simple data which can be stored using Key-Value pairs, you can make use of Shared Preferences, or use files for storing some data. But, for more complex data, you will need to use databases. Android provides us with SQLite and has also recently come up with a new library called Room which provides an abstraction layer over SQLite. Although I am yet to experiment with Room, I have tried using pure SQLite for a couple of my projects and it slowly becomes a nightmare to handle — with way too much repetitive code to write. The way to go for handling databases on Android is definitely Realm.


Image loading-

Image loading


You would think that loading images on Android is a simple thing. It can be if you want to load just a single image here and there. All you need to do is write a single line of code —


But, when you load multiple images in this way, you soon realize that your app starts running out of memory. So you look around on the internet and add a few more lines. But now you need to load an image from an URL. So you need to add a few more lines of code. But till the image loads, your UI freezes — so now you need to load it in the background.

This is just the beginning when it comes to loading images on Android. There are even more problems when you want to load a circular image, have a placeholder till the image loads over the internet, cache images that load frequently and so on.

There are 2 popular libraries — Glide and Picasso — which take care of all your image loading problems. I prefer to use Glide since in my experience it has better cache and memory management, and better customization options. All you need is 1 line of code –





UI and UX-



You obviously want your app to look beautiful and clean, and provide a smooth experience for your users. Google has defined a nice set of guidelines for its Material design for building a good, stable Android App. Almost all the elements that are described in the Material design specifications are available in the standard Android Library.

My suggestion for you is to try to use the standard Android design libraries wherever you can — they are most likely to work best with all the varied device sizes and specifications that Android has.





Android is quite clunky when it comes to mapping UI elements from XML to Java. One of my favorite examples to emphasize this is —

Toolbar toolbar = (Toolbar) findViewById(

That is too much code just to access a toolbar from a view. Although starting with API 26, it has become slightly less clunky since you no longer need to cast your views to the correct type, it still does not result in very clean code.


Butterknife solves this problem for you. You can have all your View bindings together in one place at the top of your activity —

@BindView( Toolbar toolbar;

@BindView( TextView title;


Leak Canary-

Leak Canary


Leak Canary is a memory leak detection library that you must use before publishing your app to the Play Store. It is very easy to use and helps you detect memory leaks that can potentially make your app laggy, or even crash because of OutOfMemory exceptions.




In conclusion, if it is a task which is required to be done in a standard App development there will be a good Android library for you to use. Always prefer libraries which come from reputable sources. And as all Android developers know — Jake Wharton and the engineers of Square are rockstars.

About RemotePanda

RemotePanda is a personalized platform for companies to hire remote talent and get the quality work delivered from the city Pune. The resources in our talent pool are our close network connections. While connecting them with you, we make sure to manage the quality, growth, legalities, and the delivery of their work. The idea is to make remote work successful for you. Get in touch with us to know more about Android libraries and also if you want to hire an Android app developer.

Creating Your First GoLang Project

Creating Your First GoLang Project


Enter the name of the project and choose your workspace location.

After creating project your IDE screen will appear like this –





You have to create your folders and .go files in src folder only.

Step 1)Now right click on  src folder→ New→ Folder



Step 2) Then right click on the main (folder created by you) folder→ New Go File




Here Enter your go file name with .go extension and choose the Command Source file option. The first option will create empty main functions and Simple Web Server option creates Simple Web Application.


Go Source File


Create Go file in the src/main folder of your project with extension .go




The folders like and other ones will be created as you download the dependencies.

Here you can write your code. For example –

Golang Code


Now for executing this program, you need to build the project. So double click on the build option as shown below –





It will build like this and generates the main.exe binary file in bin package.




Sometimes while building project, you will face build errors like –

go project errors


So check the message and identify which package is missing and then go to command prompt and type the >go get

So for the above messages, enter below commands →

go get -u

go get -u

go get

go get

go get

go get

go get

go get

Now again try to rebuild it and it will create the main.exe file in your bin folder of project file for example – Main.exe


Step 3) Now for running your project

Right click on your project→ Select Run As→ Run Configurations



Then select the project and package to build i.e. main

golang demo

Select your project by clicking on Browse

golang demo


Step 4) Now, select the package to build


golang demo


And then click on Run so that your Go program will execute


go program


We can also execute the go program by going to the main pkg of project and type –

> go run main.go command

golang command


Step 5) Again if you need more programs inside, follow the same procedure


code completion


Go Commands –

go commands


go build→  builds go code; if code is package main, it creates  a binary executable in the main folder & if code is just a package then it builds it and throws away the binary

go install→  builds and install go code; if code is package main, it creates binary executable and drops in workspaces’ bin folder; if the code is a package, it build it and keeps in pkg folder

import→  import path is everything after “src ” folder in your workspace. You can alias packages in your imports

If you want to debug your project then select your project → Right click→ select Debug As Application as shown below

Go coding


After this, you will get an error – Error with command:gdb –version


go error


Now download the gdb for windows from below link and add to its debugger configuration

Select Project→ Right Click on Project→ Select Debugger tab from the window

golang debugger


Now your project will debug properly.



As you now know how to create your first Go Project, check out our next chapter on Language Fundamentals

About RemotePanda

RemotePanda is a personalized platform for companies to hire remote talent and get the quality work delivered from the city Pune. The resources in our talent pool are our close network connections. While connecting them with you, we make sure to manage the quality, growth, legalities, and the delivery of their work. The idea is to make remote work successful for you. Get in touch with us to learn why RemotePanda is the best fit solution for your business requirements.

How to install go?

How to install go?

how to install go


This is a series of blogs on Golang in which we will be narrating everything from an introduction to GO, Installing Go till Developing Go application on Aws server .in a series of 10 chapters which will be uploaded every week.

Let us start with the first chapter !!!!


What is GO?


“Go will be the server language of the future.” — Tobias Lütke, Shopify

It is a Free and Open Source programming language created at Google Inc. in 2007 by Ken Thompson (B, C, UNIX, UTF-8), Rob Pike(UNIX, UTF-8) and Robert Griesmer (HotSpot, JVM)

Go is created by leading tech giant Google. It is designed by Google to solve their problems of supporting scalability and effectiveness. Those are the issues you will face while creating your own servers.

Go (Golang) is Procedural, Imperative, Modular, Object-Oriented, Statically typed, Garbage Collected, Compiled programming language with syntax similar to the family of  C languages (C, C++, C#, Java, JavaScript) & CSP style concurrency features. Programs are created using packages, for efficient management of dependencies. Go programming implementation use a traditional compile and link model to generate executable binaries. The Golang announced in 2009 and used in some of Google’s production system.

Go Program can be in length from 3 lines to millions of lines and it should be written into one or more files with the extension “.go”.  For example, hello.go.

You can use “vi”,”vim” or any other text editor to write your go program into a file


Go is fast:

  • to learn

  • to develop

  • to compile

  • to deploy

  • to run



Bonus Advantages:  

  • Golang has the speed of compiled language, but the feel of an interpreted language

  • Golang can make connections with thousands of users with a single instance only.


Valuable resources of Golang (by Todd McLeod)


Books on Golang


Features of Golang

Multicore processing:

Most of the programming languages like Python, Java supports multithreading but the problem is with concurrent execution, thread- locking, race conditions, and deadlocks. This makes hard to create a multithreading application.

For example, when we are creating a new thread in java it will consume approx 1MB heap and for multiple thread creations, it will put tremendous pressure on a heap and so will cause JVM not responding or shutdown.

So, Golang has developed by keeping this concurrency feature in mind. Go has goroutines instead of threads which consumes 2KB of memory from the heap.

goroutines have faster startup than thread.


MicroServices Support:


Today all applications have no. of external services like databases, queues, caches. Go uses async I/O so that application can work with any no of services without blocking web request.

Other Features Include –

  • Super performance

  • Clean Syntax

  • Garbage Collected

  • Concurrency

  • Powerful Standard Library

  • Open Source

  • Portable

  • Safe

  • It compiles fastly without makefiles, integrates with Git for distributed package management, and formats code with gofmt.

Go based system now runs on 400 servers,200+ million real-time connections & 10 billion messages daily.

Many big companies are using Golang for their projects

  • Google

  • DropBox

  • SoundCloud

  • Docker

  • Cloudflare

  • BBC

Features of Golang


Installing Go

To install Go, we need to go through the below steps.


For Windows, we need to use commands from Git Shell i.e. Terminal Emulator for distributed package management (optional). So we need Terminal Emulator for that.

Terminal Emulator-Git

Download and install git for Windows to download go packages. We can also use the command prompt for the same. Now open it and test it using some basic terminal commands.

Installation Insights

Download Golang:

You can Download the Go lang binary release. Download Golang distribution based on 32bit and 64bit OS

Go workspace

Certain folder structure for Go development

Create a Project Folder having a name where your project will reside

For example,


E:\golangdemo  (Name of my Workspace)

                                  bin folder (binary exe file of project)

                                   pkg folder (.a Archive file à precompiled pkg file)

                                  src folder (Source code files)

                                   folder(downloaded dependencies)

                                   folder (downloaded dependencies)


Search for go packages

To download Go packages use the following syntax –

→go get  

for ex. > go get (fully qualified pkg name)

To know more about go commands type > go in cmd prompt

Environment Path Variables-Windows

After creation of Go workspace set the Path variable of Go installation by following these steps –

Right, Click on MyComputer/ThisPC→Properties→ AdvancedSystem Settings →EnvironmentVariables→New→



Search Package


Here you need to set GOPATH and GOROOT for both User variables and System variable.

GOPATH→ Your workspace path

GOROOT→ Installed Path of GO

To check environment path variables use below command in cmd prompt –

→   env path variable stores the path to some location of a computer

Development Environment

Most popular IDE’s (Integrated Development Environment) used for Golang development are Eclipse, WebStorm, atom.

We are going to use Eclipse IDE here

  • Eclipse

  • GoClipse plugin

  • Creating new Go Project || Package || Library

How to download and install Goclipse plugin to your eclipse –

In the Eclipse, right click on Help Menu→ Eclipse Marketplace→ search for ‘Goclipse’ and install it.

go root

After the installation,

Step 1) Go to File Menu→Go Project→Enter Project Name and choose default location as your workspace location

Go Project Menu


Your project structure will be like this –

Project Explorer


Step 2) Go to windows menu of eclipse→select Preferences→choose Go→Tools→Click on Download and it will download the dependencies like gocode, guru, godef, gofmt and click apply

Windows Eclipse


Step 3) click on the Download button for each of these paths.


download eclipse


While downloading check the console




Step 4) Now your Go installation and configuration is done.

Make sure you do not miss a single step.

For more information on Golang, you can refer below links –



RemotePanda is a personalized platform for companies to hire remote talent and get the quality work delivered from the city Pune. The resources in our talent pool are our close network connections. While connecting them with you, we make sure to manage the quality, growth, legalities, and the delivery of their work. The idea is to make remote work successful for you. Get in touch with us to learn why RemotePanda is the best fit solution for your business requirements.