It is hard to recommend Python in production

I started writing in the 2010s when Python 2 was going to be deprecated and Python 3 was too early to support. Python might have died there and then but was picked up by the data science and machine learning community, so, it survived. Running Python in production comes with various gotchas though. Python is resource-intensive Let’s consider a simple Docker image containing “Hello World”. Docker 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 # Build: docker buildx build -t python-fastapi -f Dockerfile_python . # Size: docker image inspect python-fastapi --format='{{.Size}}' | numfmt --to=iec-i # Run: docker run -it --rm --cpus=1 --memory=100m -p 8000:8000 python-fastapi FROM python:3.12-slim AS base WORKDIR /app RUN pip3 install --no-cache-dir fastapi==0.115.11 uvicorn==0.34.0 SHELL ["/bin/bash", "-c"] RUN echo -e "\ from fastapi import FastAPI\n\ app = FastAPI()\n\ @app.get('/')\n\ async def root():\n\ return {'message': 'Hello World'}\ " > /app/web_server.py ENTRYPOINT [ "uvicorn", "web_server:app", "--host=0.0.0.0", "--port=8000", "--workers=4", "--limit-concurrency=32"] And a similar web server in Go. ...

How to setup Go packages under monorepo

Let’s say you want to have two Go packages pkg1 and pkg2 in a monorepo setup. Here’s what a good project structure would look like.

Generics in Go

Generics in Go were added about a year back in Go 1.18. In my experience they are great and they fix one of the biggest roadblocks in terms of writing reusable code in Go. I’ll illustrate that with an example. First, do ensure that you have at least Go 1.18 Bash 1 2 $ go version go version go1.19.1 darwin/amd64 Let’s consider a simple case of implementing a Map function in Go that maps an array (well, a slice) to another array (again, actually, a slice). ...

Inheritance in Go language

Go language does not have the concept of a class directly. It, however, has a concept of an interface as well as a struct. I’ll illustrate how this can be used to build most of the inheritance constructs that a language like Java or C++ offers.

Infinite network timeouts in Java and Go

Java made a huge mistake of having no network timeouts. A network request can block a thread forever. Even Python did the same . The language designers should have chosen some conservative appropriate numbers instead. What’s surprising is that the Go language repeated it! Here’s a simple demo