Below you will find pages that utilize the taxonomy term “golang”
Posts
Kind of method overriding in Go
Go’s approach to Object Go is a fairly simplistic language and doesn’t come with inbuilt classes and other features that most object oriented programming languages have. It gives you building blocks in the form of structs and it’s upto programmer to design the abstraction around it. There is no inheritence - Go takes a very strong stance on composition over inheritence camp. (even other languages have practitioners who preach composition over inheritence but it’s not strictly enforced).
read morePosts
Currying in functional programming
Currying Currying is an idea of decomposing a function and making the expression more clearer. (Note: it’s just expression decomposition and not execution)
Example In Go: package main import ( "fmt" "strings" ) func main() { fmt.Println(someComplexOperation("hello", "there", "programmer")) fmt.Println(someComplexOperation("hello", "there", "manager")) fmt.Println(someComplexOperation("hello", "there", "CEO")) // Currying this function // By looking at the fuction we see that it can be decomposed, first step of computing from first 2 arguments // can be done and reused.
read morePosts
Loop Iterator variable scope in golang
Per Iteration Vs Per Loop In most of the languages, the loop variable (iterator) has a per iteration scope, meaning in each iteration a new copy of that variable is made. But in golang it’s the same variable that has the scope throughout the loop. All the changes (increments) apply to the same placeholder and if you are temporarily capturing them and spawning go routines or creating a function placeholder (for later execution) you start to see unexpected consequences.
read morePosts
Struct Embedding, JSON Encoding in GO
Embeding a struct (just writing the type) creates a “has a relationship” with the parent. If the child implements any interface parent can directly invoke those methods. If there are more than one embedding and they implement a common method it’s okay as long as we don’t attempt to directly invoke it on parent (trying to do so results in compilation error - ambiguous selector) While encoding json (marshalling), encoder internally checks if the type implements json.
read morePosts
Parallelism, Concurrency And Golang
Concurrecy Vs Parallelism (Go-lang Example) This is the general understanding of concurrency vs parallelism.
Parallelism: Having multiple threads do similar task which are independent of each other in terms of data and resource that they require to do so. Eg: Google crawler can spawn thousands of threads and each thread can do it’s task independently.
Concurrency: Concurrency comes into picture when you have shared data, shared resource among the threads. In a transactional system this means you have to synchronize the critical section of the code using some techniques like Locks, semaphores, etc.
read morePosts
Idea of 'closure' in functional programming
Closure The inner function has access to variables which were in the enclosing scope even after that ’ennclosing scope’ execution is over. (Inner function gets a copy) This is my attempt to understand why is this such an important concept in functional programming, why is it named so and so on… Functions are first class citizens In functional paradigm of programming functions are considered as ‘first class citizens’. This means functions can be
read more