Go slices mind-twister

This snippet of code got me off guard. Having a somewhat decent experience with golang I could not explain what is it doing and it took me embarrassingly a lot of time to figure out a sound explanation for what was going on. After I figured out the answer, I think that my sleep deprivation just played tricks on me. Still let’s dig into this. Down below is the same snippet but with a slice of integers for simplicity:...

May 5, 2024 · 4 min · 836 words

Case of a leaking timer in go

It was only an accident that I read a post on ArangoDB site and found the same leak in one of our projects at work. So this is going to be quite short, but nevertheless I want for have it in form of a blogpost. Here is how leak looked like: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 package main import ( "fmt" "runtime" "time" ) func main() { messags := make(chan string) for { select { case msg := <- messages: // do smth with msg fmt....

November 13, 2022 · 3 min · 449 words

VIM cheat sheet

These are my notes on “Mastering VIM” by Ruslan Osipov. Also contains my own knowledge. dd — delete line cc — delete line and go into INSERT mode Movements uppercase is for “words separated by whitespace” e or E — move to the End of the word w or W — move between Words b or B — move Back _ jump to the beginning of the line :N where N is a number line....

June 24, 2022 · 3 min · 493 words

SOLID Go

SOLID is a famous cargo-cult that is used to poke “bad” code during code review. Jokes aside there are some solid, pun intended, ideas within SOLID. This post is yet another attempt to dismantle this set of principles and understand them better. The SOLID stands for(pasted from wiki): S ingle-responsibility principle: “There should never be more than one reason for a class to change.“In other words, every class should have only one responsibility O pen–closed principle: “Software entities … should be open for extension, but closed for modification....

June 6, 2022 · 3 min · 558 words

Notes on Garbage Collection in Golang

Garbage Collection is a process of freeing memory that is allocated and contains some data that is not being used. Notes: by doing escape analysis GC mechanism decides what goes to heap and what stays on stack use -gcflags '-m' flag to get escape analysis info, e.g. go run -gcflags '-m' main.go another way to look into what GC is doing during runtime is to run program with GODEBUG=gctrace=1 GC runs consurrently with main program running main running program is called “mutator” Golang Garbage Collection uses “tricolor algorithm” otherwise known as tricolor mark and sweep algorithm....

June 5, 2022 · 1 min · 141 words