Tag: programming

Untyped Constants in Golang

Golang is extremely explicit with types. It supports constants of a type. But how about a const 2 or hello. What type would they assume!? Go solved this problem with untyped constants. Untyped means: A constant’s type depends on the type of assignee variable. The assignee’s type must […]

How a Regex Engine Work?

A regular expression defines a set of string. A regex engine matches a pattern against input and returns true/false for the condition that pattern exists in the input. I have got a C++ implementation of a regex engine which uses simple constructs of matching the following: A single […]

How to Write Clean Code?

Basic Hygiene Leave the place cleaner than you got it. Naming Convention Do one thing in a function. Name should reflect the action. Function name is a verb. Declare literals ([a-z]+, [0-9]+) as constants. Functions The function should not exceed twenty lines. Each if, else, while statement can […]

How to Write a Conference Scheduler

The conference schedule is an NP problem since it is O(2**n). A greedy approach is pragmatic to solve the problem. We can pick various strategies to prepare a schedule such as the biggest talk first, smallest talk first, random selection, etc. The Python code uses the Longest talk […]

Notes on String & Encoding Techniques

String and their encoding decide the languages the code can support. Introduction We have many languages and their symbols that need more than 8-bits (ASCII) for binary representation. Encoding adds semantics to a set of bytes. Unicode is a table of all characters and their numeric equivalent. Since […]

The Best Go Library for Redis

There are two popular choices: go-redis redigo I prefer redigo over go-redis. Cons with go-redis Not enough documentation for APIs Difficult to understand naming conventions for APIs I’m still finding how to refresh expiry time of a key using go-redis Needs Cmdable interface for calling Redis commands. The […]