My Favorite Programming Language

TL;DR: My favorite programming language is Go. Here’s why. Correctness and Reliability out of the Box I have several years of experience with Python. I can say that Unless a feature is accompanied by comprehensive test coverage, the maintainer should always deploy it carefully. However, well-structured Go code which compiles already passes 20-30 percent of tests otherwise we should have written and passed for a similar Python software. ...

2024-10-31 · Amir Ehsandar

Type Safe Queries in Go

In this article, we will discuss how to write type-safe queries in Go. We will use the sqlc tool to generate Go code from SQL queries. This will allow us to write type-safe queries in Go. The main advantage of using sqlc is that there cannot be any runtime errors due to type mismatches in the queries as the parameters and returned row types are determined during the compile time. We’ll also discuss how to use sqlc alongside pgx to implement different scenarios like transactions, connection pools, CTEs and more. ...

2024-10-11 · Amir Ehsandar

Go code generation approaches

Code Generators It’s a quite common pattern in Go projects to use code generators. Code generators or in short term, codegens are used to provide type safety and eliminate runtime unnecessary processing. Without codegens, we need to use reflect package at runtime. Our Problem Imagine we have a json serialized byte stream received from a user or read from a file. 1 2 3 4 { "first_name": "Amir", "last_name": "Ehsandar" } How can we Unmarshal this arbitrary data structure into a struct? In this article, we discuss two different approaches to unmarshal this serialized binary into corresponding struct. We also compare three different stages for generating codes, on developer’s machine, on CI or every time before build process begins. ...

2023-07-14 · Amir Ehsandar