It’s heavily based on C, but designed to be more concise and secure. Go has become increasingly popular for seasoned developers and new programmers alike,
used in many open source and commercial software applications.
Some notable companies using Go within their applications include Google, Dropbox, CloudOS, MongoDB, Docker and Uber.
Go Language Basics
Go is a statically typed, compiled, garbage-collected, concurrent general purpose programming language. Go is considered as an object oriented programming language and it uses object composition instead of class inheritance.
Go was based on several languages besides C: Pascal, Modula, Oberon, Newsqueak, and Limbo.
It is a traditionally compiled, object oriented, functional language that features static typing, garbage collection, concurrency, memory safety, and high readability.
Some of the major advantages of Go include:
- Concise, simple syntax.
- Extremely fast compile times.
- The ability to divide routine threads into sub threads, allowing for a high degree of concurrency.
- Built-in support for strings and maps.
- Go includes a huge standard library, including its own built-in web server.
- The language supports most major operating systems and computer hardware.
Objects In Go
Since a standard definition does not exist, let’s use this one, “An object is an abstract data type that has state (data) and behaviour (code)”.
Go doesn’t have something like `object`, even though it does have a type that matches the same definition of a data structure that integrates both code and behaviour.
In Go this is called a ‘struct’.
With struct we define a new data type containing the name of fields (attributes) that will keep the “state” of the object. To implement the behaviour of this object in Go,
we use functions bound to a pointer of this struct. Here’s an example to illustrate it:
Relationships between Objects In Go
Instead of inheritance Go strictly follows the composition over inheritance principle. Go accomplishes this through both subtyping (is-a) and object composition (has-a) relationships between structs and interfaces.
The mechanism Go uses to implement the principle of object composition is called embedded types. This way we have a field that is a subtype of other object, but this filed remains in a different entity.
Because of that Go provides two alternatives, “Pseudo sub typing” and “True sub typing”.
We accomplish this pseudo is-a relationship in go using what is called an Anonymous field.
Over the next posts I will bring you a more detailed explanation about this concepts while introduce you data types and language characteristics with some examples on each topic.