The Go programming language introduction in the form of questions and answers.
This document is created using my own Go notes. The official Go website has very good documentation, including FAQ.
I'm trying to keep my notes simple and concise. I believe these notes will help beginners to get familiar with Go quickly. Contributions and suggestions are most welcomed!
Note: I've just started learning Go (June '17). This document will grow as I learn more.
Go is an open source programming language (which means source code for its compiler, libraries and tools is freely available to anyone. Go here (pun intended): https://github.com/golang).
Go is a compiled (desinged for fast compilation), statically typed language (similar to C, C++, Java). It has garbage collection (automatic memory management). It has built-in support for writing concurrent programs.
Other Gyan: One of the shortest complete sentences in the English language is 'Go.'.
Go design was started in September 2007 by Robert Griesemer, Rob Pike and Ken Thompson at Google. It was publicly announced and also open sourced in November 2009. Go version 1 was released on 28th March, 2012.
- Fast compilation
- Easy to use dependency management
- Utilize the emergence of multicore processors by providing buit-in easy to use concurrency features
- Simple type system. (trying to make it simple by not supporting type heirarchy)
- Developer productivity
As a starter, use the Go playground. There is another similar un-official service.
You can also download and install the required tools on you local machine from Go website.
This comparison is only meant for showing how concise Go compared to other languages. Please do not translate your C++ or Java programming thinking while writing Go programs.
Feature | Go | C++ | Java |
---|---|---|---|
Statically typed | ✅ | ✅ | ✅ |
Object oriented programming | ✅ | ✅ | ✅ |
Variadic function | ✅ | ✅ | ✅ |
Defining constants | ✅ | ✅ | ✅ |
interface |
✅ | ✅ | ✅ |
Statically compiled | ✅ | ✅ | |
struct |
✅ | ✅ | |
λ functions/Closures | ✅ | ✅ | |
In-built concurrency support | ✅ | ||
Implicit implements |
✅ | ||
Designed for fast compilation | ✅ | ||
Anonymous functions | ✅ | ✅ | |
datatype rune |
✅ | ||
A case body breaks automatically | ✅ | ||
Function can return multiple values | ✅ | ||
Declaring multiline strings using ``````` | ✅ | ||
can return the address of a local variable | ✅ | ||
Arrays are values (assigning copies all the elements) | ✅ | ||
The size of an array is part of its type | ✅ | ||
& address-of operator |
✅ | ✅ | |
Garbage collection | ✅ | ✅ | |
Pointers | ✅ | ✅ | |
while |
✅ | ✅ | |
do { } while |
✅ | ✅ | |
class |
✅ | ✅ | |
try { } catch() { } |
✅ | ✅ | |
Generics | ✅ | ✅ | |
Type inheritance | ✅ | ✅ | |
Function overloading | ✅ | ✅ | |
Explict implements |
✅ | ✅ | |
; at the end of lines |
✅ | ✅ | |
?: Ternary operator |
✅ | ✅ | |
Operator overloading | ✅ | ||
Arrow (-> ) dereferencing |
✅ | ||
final, abstract |
✅ | ||
virtual, friend |
✅ | ||
this |
✅ | ✅ | |
static |
✅ | ✅ | |
Default function arguments | ✅ | ||
Pointer arithmetic | ✅ |