Dev Journal

Development and programming focused posts accumulated over the time.

Dynamic generation of informative `Enum`s in Python

Ignacio Vergara Kausel published on

3 min, 444 words

Since I started learning some Rust and getting to know its enums, I've been very into using Enums in Python. And while enums in both languages are very different, they're close enough for most of my current use cases. Moreover, within Python, Enums are used in frameworks like Typer (CLI) and FastAPI (API), where they are used to provide validation to input within a set of possibilities.

Read More

Categories: dev

Boolean arguments to functions in Python

Ignacio Vergara Kausel published on

2 min, 266 words

Recently I did read the following short piece from M. Fowler regarding the use of boolean flags in function signatures. I'll wait while you read it... done? Good!

As a general rule, I completely agree with him. They can be confusing, and should, in general, be avoided (easier said than done). But the article got me to reflect on this advice in the context of Python.

Read More

Picking up from other languages

Ignacio Vergara Kausel published on

9 min, 1623 words

After many years of doing Python, first as a hobbyist and then in a professional setting, I've had to do some amount of Go programming. Also, I've been trying to explore other languages, primarily Rust, but have been touching some C while following some projects ([1] and [2]).

Read More

Deeper into dataclasses

Ignacio Vergara Kausel published on

10 min, 1947 words

Most articles cover the basics of dataclasses, this is an attempt to cover some more advanced features of this module.

Usually, examples using the dataclasses module in Python are rather simple in the use of its features. That by itself is completely fine, but sometimes the implementation can be very tedious and cumbersome. However, the dataclasses module offers ways to be smarter, which are rarely talked about. With this article, I want to change that. Thus, this article doesn't cover topics like when and how to use them. There is plenty of material on the Internet to learn about that.

Read More

Exploring Rust generics

Ignacio Vergara Kausel published on

8 min, 1552 words

For a while I've been interested in Rust, reading articles and books, and trying to do some small exercises in it, but in general still rather superficial. Now, after reading the following the second part of a series of articles on *Scientific computing in Rust, I decided to use that example to explore a bit more and challenge myself. The article mentions very early the following

But what happens when someone else comes up with a new numerical type with a legitimate concept of addition and multiplication (e.g. complex numbers)?

to motivate exploring generics, but the scenario of complex numbers was not explored. Thus, I wondered how to use the example function used in it, namely generic_scalar_product, with a more complex type., e.g., complex numbers.

Read More