The curious case of Python's context manager

Python’s context managers are great for resource management and stopping the propagation of leaked abstractions. You’ve probably used it while opening a file or a database connection. Usually it starts with a with statement like this: with open("file.txt", "wt") as f: f.write("contents go here") In the above case, file.txt gets automatically closed when the execution flow goes out of the scope. This is equivalent to writing: try: f = open("file.txt", "wt") text = f.write("contents go here") finally: f.close() Writing custom context managers To write a custom context manager, you need to create a class that includes the __enter__ and __exit__ methods. Let’s recreate a custom context manager that will execute the same workflow as above. ...

Reduce boilerplate code with Python's dataclasses

Recently, my work needed me to create lots of custom data types and draw comparison among them. So, my code was littered with many classes that somewhat looked like this: class CartesianPoint: def __init__(self, x, y, z): self.x = x self.y = y self.z = z def __repr__(self): return f"CartesianPoint(x = {self.x}, y = {self.y}, z = {self.z})" print(CartesianPoint(1, 2, 3)) >>> CartesianPoint(x = 1, y = 2, z = 3) This class only creates a CartesianPoint type and shows a pretty output of the instances created from it. However, it already has two methods inside, __init__ and __repr__ that don’t do much. ...

2025

June 16 Using sed to extract a patch from a file While running the OpenAI Codex CLI locally, I came across a sed command that prints specific lines from a file. The agent often uses this command to output a portion of a file: sed -n '12,15p' <filename> This prints lines 12 through 15 of <filename>. March 29 dotGo 2014 - John Graham-Cumming - I came for the easy concurrency I stayed for the easy composition I had to watch this twice to fully appreciate it. John Graham-Cumming crams a 40-minute talk into 14 minutes. First, he shows how Go’s basic types and stdlib make writing a DNS lookup program quite trivial. Then he walks through how he generalized it with a simple interface. The code can be found here. ...

2024

December 31 Exploring network programming by building a Toxiproxy clone – Jordan Neufeld Great talk by Jordan Neufeld on building a toy proxy server in Go that adds latency between upstream and downstream connections. It sits between a client and server, introducing delays, dropping connections, and simulating errors for chaos testing. December 26 Reflecting on life – Armin Ronacher The best way to completely destroy your long term satisfaction is if the effort you are putting into something, is not reciprocated or the nature of the work feels meaningless. It’s an obvious privilege to recommend that one shall not work for exploitative employers but you owe yourself to get this right. With time you build trust in yourself, and the best way to put this trust to use, is to break out of exploitative relationships. ...

About

Redowan Delowar rednafi Hey there! I’m Redowan Delowar - also go by the handle “rednafi” on the web. I dabble in platform engineering, which mostly means working with giant distributed balls of mud and fighting to keep the house of cards from falling over. Lately, I’ve been focused on persistence, resilience, and observability - or whatever else is currently on fire. When not at the keyboard, I’m probably running or reading sci-fi. ...

Blogroll

Friends Anton Zhiyanov Matthias Doepmann Preslav Rachev Frequent stops Brandur Charity Majors Dan Luu Drew DeVault’s Blog Fabien Sanglard’s Website Harmful Stuff Julia Evans Matt T. Proud Peter Bourgon Simon Willison’s Weblog

Maxims

Wisdoms, aphorisms, and pointed observations - fragments I find myself frequently quoting in conversations about software, philosophy, and ways of working. Chesterton’s fence Reforms should not be made until the reasoning behind the existing state of affairs is understood. Gell-Mann amnesia effect The Gell-Mann amnesia effect is a cognitive bias describing the tendency of individuals to critically assess media reports in a domain they are knowledgeable about, yet continue to trust reporting in other areas despite recognizing similar potential inaccuracies. ...

Talks

Oratories on paraphernalia. Go interface segregation redux - Dec 3, 2025, GDG Berlin Slides Video