Posts

Stack Using Golang Generics

Image
  With the recent introduction of  generics in Golang , they have proved themselves not only elegant and simple, but also very efficient, check out the performance characteristics here . Now it is time to demonstrate their power in creating flexible data structures in this post. As promised in a later post , we are going to implement a stack in this post. The rest of this post is organized as follows: what is a stack stack methods implementation in Golang testing our stack NOTE THAT ALL CODE SNIPPETS FOUND IN THIS POST CAN BE FOUND HERE What is a Stack Stacks are simple data structures that powers a great deal of modern computational systems like function calls in compilers themselves, LRU policy of memory block replacements, bracket matching problems and many many more. Stacks were first introduced in 1964 by Alan M. Turing and they were gaining popularity ever since. A stack acts as a first in last out data structure most commonly known as LIFO. In layman terms this means it is a dat

Golang Generics Performance Evaluation and Implications

Image
  Generics is the latest upcoming feature in Golang. Introducing high level elegant syntax along with infinite possibilities. If you need an introduction kindly visit our post on Golang generics . Unlike the previous post , This post is more concerned about evaluating the performance of Golang Generics and some future perspectives and implications. Any source code snippets used in this post can be found here . The rest of the post is organized as follows: Introduction to generics Benchmark experiments strategy Benchmark results Implications on Golang future Introduction to generics Generics has been around and used extensively (specially when writing libraries or frameworks) in many programming languages like c++, c#, java. However, generics are known to have some extra computational cost to explicitly typed code. With that in mind, it has been always a good idea to write in generics rather than explicit coding due to its huge advantages in readability, maintainability and code reuse.

Generics In Golang

Image
  Golang is an emerging technology that took the development world by storm. Introducing rapid software development that is consistent, strongly typed, insanely fast performance, and simple concurrency model; that is cheap, easy to learn and debug.  As promised by google on twitter, finally generics are introduced in Golang. This post will introduce the upcoming feature in Golang 1.18 called Generics. I'm going to assume basic familiarity with Golang. The rest of content is organized as follows: What are generics Why Golang? Golang before generics Generics in Golang Install Golang 1.18 Simple stack using generics Implementation in Golang. Kindly note that all code snippets used in this post are available here.  What are generics? Generics are programming concepts that applies to functions, classes, and methods. That allows the usage and declaration of strongly typed software artifacts with complete independence on the type/s of their parameters. This can be achieved in a two step p