Skip to main content


Showing posts from June, 2019

Do you support us?

Business address

Compose complex types

Welcome everybody, I'm happy after reading comments which you post on subreddits. Thankyou. Today, i will write my article on compose complex types but in end i give you a simple task, can you do that? Types:       In golang we create types in two ways       1.       type-keyword  name-keyword  datatype                type                Meter           float64       2.     by using struct which you are familiar about.    Let's start with simple example, so that we can understand how to do that. Problem: I have two CEO, one CEO is elon musk and other is mark zuckerberg. Both CEO are also person and own attributes such as name or company.     If you know Object oriented approach you might think like this person is the person class and ceo is derived class. However this is not pure object oriented language, so that is not a solution. How can i solve?  Oh Yeah, I build a struct type person, that hold all the attributes which person have. But the question what i do wi

Do I, receiver, nil argument?

Hello,  Welcome back. This is quite interesting topic. Do I pass nil argument? The answer is yes. But How? Nil Arguments?           Here is my code </>      package main import ( "fmt" ) type List struct{ data int tail *List } var list List func(r *List)Insert()( *List) { if r == nil{ panic ("Empty List") } return r } func main() { var l *List = &list = 3 l.tail = nil p := l.Insert() fmt.Printf("%p", p) fmt.Println( h  := &list = 1 h.tail = p c := h.Insert() fmt.Println(, c.tail) }           If you want to check either your data structure it is empty or full. The above example show a demonstration, how the nil arguments pass or receive by methods. I want to create my own list for this example.       If , you want to curious then you can  Run  this code. Thankyou, Have a great day.

Methods Receiver as a reference

Hello, Welcome back; Today , we create new type of method receiver. When a function receive a value type parameter, on heap it will create copies of all the parameters, you pass. To avoid this problem, function receive reference type variable. Such as pointer, channels. Pointers have following advantages over variable. It Directly access, no copy , change in original value.            Method Receiver Pointer:             If you can write a code in C. Then you know, methods are not inherit C or Java Language. It's inherit from unix messages.                        func (c *Cal) Sum(y int) int{ // code }             Cases :         There're following cases that are exit  1. If a method receiver and method argument both are T or *T type , it directly access. 2. If a method receiver is T type, however method argument as *T type. then  it need reference to access (&) 3. If a method receiver have *T and method argument as T type then dereference (*). p

Object Oriented paradigm and golang

Welcome back , I hope you enjoy previous article. If you write a code before most of us in academics or enterprizes follow object oriented paradigm. In Java, c# and other languages "class" keyword represent this is an object oriented paradigm. But in golang there is no class keyword exist. "Is Oop Exist?" Generally speaking golang is not object oriented language, however it support oop at some extend. You will see just in a moment. Methods Working : First of all in oop there is class who have methods and properties. Methods are used to set properties. If you want to access class you have a reference of our class. Perhaps, in golang oop is little bit different. In go, you have a method or a reference of a struct. Now the question what is method? Method is just like function, but it has one additional parameter called receiver, which is the same type of struct. Methods usually are fast and efficient. Methods give you direct access to structs reference.       

Panic is an art

Writing a good program  Panic Joke Hello, guys after a long time, I'm a writing my next blog called panic is an art.  I will start in a moment. But First we revise our knowledge, it is mandatory for this article.  Defer: As you know defer means free your resources or clean your memory before quite. You already know defer statement  will change program execution. Defer statement work in LIFO order. Multiple defer functions call gorounties. Goroutines are different from normal flow, it's look similar jump command in assembly language. I will show you how to play with goroutines. Panic: Panic is a built-in function, provide by golang language. Panic is just like exceptions, however exception concepts are not using in golang. Panic is very useful in debugging.  panic(error). Panic is also very useful when rare condition maybe or may not be possible. Panic and defer follow side by side. If you crash your program, compiler tell