Go Programming Language

Go (or Golang) is a formal and multipurpose programming language, developed by Google, whose design was inspired by C, Pascal and CSP. CSP stands for Communicating Sequential Processes, that is: a set of processes that run across many processing units (e.g CPU cores), which communicate through channels, each processing unit executes one or more tasks or functions. We will cover concurrency in more detail in future lessons.

Features of Go language

Go Programming LanguageGopher Mascot.

This is an incomplete list of features :

  • Concurrency: Concurrency is achieved with Goroutines, thanks to this feature, your program's functions can run across multiple CPU cores, and assign a different task to every single core. The good news is that different routines running on different cores can communicate with each other through channels. This helps accelerate execution speed and overall performance.
  • Object-Oriented Programming: Although Go does not have classes (in the most ubiquitous sense of the word), it certainly provides a workaround: structs and interfaces. We will see how to implement OOP with Go.
  • Strong typing: Go is a strong typed language, which means that variables have specific types, if you declare a variable lmyFloat (e.g 7.55) as float, you cannot assign a string like "Hello" to myFloat. This forces the programmer to handle errors linked to bad typing. Suppose that a user entered his name instead of his age, this either would raise an error or an exception instead of just pretending like nothing happened, which is bad: since this would lead to further inconsistencies during execution time.
  • Unused imports and variables are not allowed: At first I did not like this feature about Go, then I started to appreciate it after a while. In general, You don't use it, do not do it!, it is that simple. This keeps my code, not only clean and readable, but also faster. If you import a package or declare a variable you do not use, that would cost you some milliseconds, and if you keep repeating this habit in loop statements and functions that are used very often, then it may get worse: seconds. And you know that the more unused variables and imports the more likely bugs and errors are. That is the reason I prefer writing code while knowing that I am not making this mistake at least.
  • Fast compilation: Go is a compiled programming language, it means that your code compiles to a ready binary file that will be directly executed during production, in other words, once you finish your project, it is saved as a binary executable file, and it compiles to native machine code (e.g Linux) without the need of a Virtual Machine.
  • Pointers: Most of the time you will not need to use pointers, but believe me : sometimes you will need to allocate and free memory more wisely. The garbage collector does most of the work for you, but it would be interesting to know that you have more control over memory than you may think, for instance : that you can use a pointer instead of copying a variable to another memory. Although pointers are a good tool to have, one should always be careful with them.

Of course there are more features, although some of them are briefly described, only practice and experience will make you appreciate most of what Go (or any other programming language) has to offer. So, let us jump to the first lesson.