Ganzua is a little utility for working with Python lockfiles – inspecting and diffing lockfiles, as well as editing pyproject.toml files with information from the lockfiles. This post explains a bit of background, and offers a small tutorial. read full post (7 min) Tags: [Projects] [Python]
AI-assisted development is all the rage nowadays. I'm sceptical, but really want to give these tools a fair shot. But then I look at what these tools actually manage to do, and am disillusioned: these tools can be worse than useless, making us net-negative productive. Let's pick one of the best possible examples of AI-generated code changes. An example so good, that the Cursor Editor uses it to…
Tox is a neat tool for helping test Python projects. It automatically creates “virtual environments” that include the necessary dependencies, and can then run user-defined tools for testing. Multiple environments can be created in a declarative manner to test different combinations of Python versions + dependencies. Tox will also build packages in an isolated environment. This has been an…
Cache-aware programming can make a huge performance difference, especially when writing code in C++ or Rust. Python is a much more high-level language, and doesn't give us that level of control over memory layout of our data structures. So does this mean that CPU caching effects aren't relevant in Python? In this post, we'll conduct some basic experiments to answer this question, by accessing list…
While cleaning up some of my dotfiles, I found what may be the most cursed Python code I have ever written: raw syscalls that required parsing Linux header files. read full post (6 min) Tags: [Python] [Linux] [C]
When designing interfaces / APIs, it is easy to design the interface around the solution space. This makes such interfaces difficult to use, difficult to test, and difficult to maintain. Instead, our interfaces should allow users to easily express their intent. read full post (5 min) Tags: [Code Craft] [Python]
Virtual method calls are simple: you just look up the method slot in a vtable and call the function pointer. Easy! Well, not quite: interfaces present a kind of multiple inheritance, and things quickly become complicated. This post discusses interface method calls in C++ (GCC), Java (OpenJDK/HotSpot), C# (CLR), Go, and Rust. It is an expanded version of my answer on Software Engineering Stack…
So you've got a Perl $variable . Can we use it as an array or hash reference? If you do an online search for possible solutions, you'll find a number of suggestions, most of them wrong. TL;DR: checking if ref $variable eq 'ARRAY' is almost always a bug. Depending on your use case, you want: reftype $variable eq 'ARRAY' from Scalar::Util as a check for physical array references , or _::is_array_ref…
When does it make sense to keep integration tests separate from your unit tests, and when is it OK to make no distinction? Well, it's all about getting fast feedback. read full post (4 min) Tags: [Testing]
This article explains the difference between dynamic dispatch (late binding) and static dispatch (early binding). We'll also touch on the differences in language support for virtual and static methods, and how virtual methods can be circumvented. read full post (7 min) Tags: [Object-Oriented Programming] [C++]
I'm currently refactoring a huge method into smaller parts. It is stock full of nested loops, maintains a complex state machine with more variables than I have fingers, and is the kind of code where I have to ask myself how I could ever think this would have been a good idea. So obviously, I'm splitting that function into smaller, independent chunks with the Extract Method refactoring…
Making your code ready to be tested Global dependencies make it difficult to properly test a piece of code. By extracting all dependencies into a single manageable object, we can easily mock the necessary services and avoid a large-scale refactor. read full post (9 min) Tags: [Testing] [C++]
There are many exciting parser technologies out there, and one of the most promising is Marpa. This post discusses how Marpa improves over commonly used parsers. read full post (17 min) Tags: [Marpa] [Parsing]
Building a simple object system out of closures Object-oriented programming and functional programming imply each other. While encoding closures as objects is a well-known technique (see the command pattern , and e.g. Functors in C++), using closures to implement objects is a bit more unusual. In this post, I will explore creating a simple object system in JavaScript, using only the functional…
Or: how to write the easy part of a compiler A Stack Overflow question asked how to translate a VB-like conditional into a C-like ternary. The other answers suggested regexes or treating it as Perl code *shudder*. But transpiling code to another language can be done correctly. This post aims to cover: parsing with Marpa::R2, AST manipulation, optimization passes, compilation, and Perl OO. In the…