Master any programming language fast

The Go Programming Language

Share
Like SyntaxCorect.com on Facebook
Be the first to rate this article

What happens when one of the biggest tech company of the world needs to get faster at developing its backend stuff without compromising on easiness, power and execution speed? You can bet: it invents a new way of doing OOP and the perfect language to implement it

Introduction

The Go programming language is a computer programing language first appeared on the scene 10 years ago (on November 10, 2009). It is a statically typed, object-oriented, concurrent, procedural programing language with automatic memory management whose main purposes are:

  1. to be a statically typed language suitable for the development of large, distributed systems and highly-scalable network servers like those usually developed in Java and C++;
  2. to be concise, productive and readable enough to be perceived "light on the page" like dynamic languages;
  3. to support networking and multiprocessing;
  4. to be compilable to native machine code without the need of external execution environments to run.

The language was created at Google by Robert Griesemer, Rob Pike and Ken Thompson.

First glance at the code

Example: The classic "Hello world" program written in Go:

Main features of Go

Technical features

Statically typed

Go is a statically typed language and has a some built-in types. Strings are immutable. Custom types can be defined with the struct keyword. Pointers to memory structures are available in Go.

Table: Go basic types

Type Notes
bool true/false
string a sequence of UTF-8 bytes (the internal rapprasentation is a slice)
int 2 bits wide on 32-bit systems and 64 bits wide on 64-bit systems
int8  
int16  
int32  
int64  
uint 2 bits wide on 32-bit systems and 64 bits wide on 64-bit systems
uint8  
uint16  
uint32  
uint64  
uintptr 2 bits wide on 32-bit systems and 64 bits wide on 64-bit systems
byte alias for uint8
rune alias for int32, represents a Unicode code point
float32  
float64  
complex64  
complex128  

Object-oriented

Despite many say that Go is not object-oriented, it is. It's just that Go implements OOP paradigms and costructs in a very new, different and unconventional way. While Go has interfaces, classes and objects are not present, still a struct can have its own number of basic type fields and/or be composed also by combining different stucts together inside a new struct and functions can be tied to the internals of structs. In the end Go offers an elegant way to do OOP avoiding all the problems of multpliple inheritance and the likes.

Concurrent

The Go language has complete support and offers language constructs to allow the concurrent execution of multiple threads within the same application, even if details of the internal mechanics of parallel execution is hidden from the programmer who is instead offered to work with high level functionalities called goroutines and channels.

Memory management

Memory management in Go is automatic. A garbage collector at run-time provides to free the memory resources allocated for the object instances that become not reachable any more by any part of the running application.

Go libraries/ecosystem

Go has a very comprehensive standard library and having Go gained good adoption and popularity some tens of thousands external libraries are already available for the language.

Performance

Go is a compiled language, its performance could surely be comparable to those of C/C++ applications. Still in Go the use of the garbage collector is mandatory and this prevents the adoption of the language for real time application development, due to the periodically pauses of the garbage collector.

Run-time support

Go needs no runtime support, in fact it's a compiled language which runs natively on Windows, Mac OS X and many flavours of Linux.

Other features

Free and open source

The Go compiler and other language tools are all free and open source under a BSD like license.

Notable softwares/platforms/products written in Go

  • Netflix uses Go for two parts of their server architecture
  • Uber uses Go for handling high volumes of geofence-based queries
  • SoundCloud leverages Go for many of the company's backend services
  • Google, which develops and mantains Go, extensively uses the language even if most uses of it are confidential
  • Facebook, DropBox, Lyft, Medium, Docker and many, many others use Go for some or many of their backend services

Conclusion

When Go first came to life Google promised that if you try it on something real that you need to develop, you'll fall in love with the language. Well, it is true. The very unconventional way to make OOP programing that Google has implemented with Go is effective and it takes very few days to get used to it. Not only, after those first few days another Google affirmation comes true: you look at the code and you instantly understand what it does. What else can one ask for a new, modern, effective and fast, both in compilation and in execution, programming language? To be created, maintained and given for free to whoever want it by one of the tech giant of the world? Oh well, you got it!