GO(Golang) programming language

Garbage Collected

Go doesn’t have concept of Classes so can’t have Inheritance.

  1. One of the main disadvantages of inheritance is the increased time/effort it takes the program to jump through all the levels of overloaded classes. If a given class has ten levels of abstraction above it, then it will essentially take ten jumps to run through a function defined in each of those classes
  2. Main disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled. This means one cannot be used independent of each other.
  3. Also with time, during maintenance adding new features both base as well as derived classes are required to be changed. If a method signature is changed then we will be affected in both cases (inheritance & composition)
  4. If a method is deleted in the “super class” or aggregate, then we will have to re-factor in case of using that method.Here things can get a bit complicated in case of inheritance because our programs will still compile, but the methods of the subclass will no longer be overriding superclass methods. These methods will become independent methods in their own right.

Go doesn’t have Generic programming.

Go doesn’t have method overloading as it slows down compilation.

Interfaces in Go is bit different.

It is not similar to C,C++ syntactically. But it can replace C and C++.

Go is not for a UI projects atleast for now.

Language specifics:

  1. Data types:

3. Very important to understand the difference between Method and Function.
The term “method” came up with object-oriented programming. In an OOP language (like C++ for example) you can define a “class” which encapsulates data and functions which belong together. Those functions inside a class are called “methods” and you need an instance of that class to call such a method.

In Go, the terminology is basically the same, although Go isn’t an OOP language in the classical meaning.

Methods in Go:

Look at this example below:

Greeting() method is actually a part of User type since it takes receiver of type User.

Functions in Go:

func function_name( [parameter list] ) [return_types]
body of the function

Returning multiple values from Function:
func swap(x, y string) (string, string) {
return y, x

Note: Go uses call by value to pass arguments. In general, it means the code within a function cannot alter the arguments used to call the function.

Go programming language provides the flexibility to create functions on the fly and use them as values.

Go programming language supports anonymous functions which can acts as function closures. Anonymous functions are used when we want to define a function inline without passing any name to it.

Interfaces in Go:

Greet function takes an interface type as argument.
User type has implemented a Name function.
So Greet function can be invoked with User instance as argument.

Concurrency in Go:

Do not communicate by sharing memory; instead, share memory by communicating.

Channels are a typed conduit through which you can send and receive values with the channel operator, <-.
ch <- v // Send v to channel ch.
v := <-ch // Receive from ch, and assign value to v.

By default, sends and receives block wait until the other side is ready. This allows goroutines to synchronize without explicit locks or condition variables.

Suffering from Knowledge Quest

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store