Skip to main content
Me

Bleating Edge

Stories about tech and a bit of my personal journey and interests


How to mock external dependencies to improve your tests in Python

Unit tests typically only test parts of your program in isolation from other units or modules. Some folks like to not mock anything and setup any dependencies before the tests and use them. But what if you're depending on a third party API outside of your control? What if the API you're using is not available at the time? Sometimes you have no choice but to mock the API. In this post, I'll show you how to mock external dependencies so you can make your tests runnable in any condition even without the API itself.

Measuring Python code coverage with the coverage package

Any decently sized project will have tests setup to make sure that each change made to the software does not break anything. Some like to practice test-driven development to improve the quality of the program and to make it testable. Regardless of whatever practice you use, these tests cover the majority, if not all functionalities that exist in the system. How do we measure coverage though? If you're a Python programmer, look no further than the coverage package!

Why stacking your PRs can speed up your team

If your team uses a strategy like trunk-based development, chances are you make small PRs that get merged and deployed quickly on the trunk. For a lot of cases, you can just wait until a coworker reviews it and you can move on to other tasks in your backlog. But what if your tasks form a dependency chain with each other? You can wait and move on to other tasks and then- oh right. The tasks depends on the previous task. Well, I guess you're stuck. Or are you?

Distributed tracing with Sentry for multithreaded applications

Perhaps the most crucial thing to do before deploying your applications to production is to make sure that you can monitor and act quickly in case of failures. A quick Google search will show you terms such as metrics, logs, and distributed tracing. For monolithic systems, the first two covers almost everything you need to track and identify issues. When you have multiple services interacting with each other, distributed tracing helps a lot, especially if you have a high rate of requests where it's hard to get anything from logs alone. What some may not realize is that distributed doesn't always mean different services. Tracing processes in different threads and correlating them is also a case of distributed tracing...well not quite but that's what we'll be discussing here. I will also show you how to do that with Sentry.

Divorcing the domain from persistence

Separation of concerns is a concept that's often mentioned when discussing maintainable code. It's also the underlying philosophy for some aspects of well-tested patterns and architectures such as domain-driven design and layered architecture. One example of how separation of concerns is applied is by separating the objects in the domain layer from the persistence layer. There are a myriad of resources that discuss the terminologies and concepts of how it looks like in the pattern. We won't be covering that in this post. Instead, I want to explain the intuition rather than the technical details and how it can help you write better code.

Building a payment system with the Strategy pattern

If you've been writing software for a while, you probably know of design patterns. It's often associated with object-oriented programming and Java has a lot of those in the ecosystem. A lot of people see it as needless abstractions that only has use in OOP languages such as Java. While I personally believe that not all of these patterns are actually that useful, one pattern is actually used a lot in production systems outside of Java whether people realize it or not. That pattern is known as the Strategy pattern and we will be using it to design a payment system.

Using bridge networks for simple and secure inter-container communications

Docker is a very convenient tool to deploy your applications to any machine with almost no effort. However, it does has some quirks that beginners tend to miss that can cause serious security issues, especially related to networking. In this post, I will cover a bit on what it means to expose container ports using Docker, why you shouldn't do it unless you absolutely have to, and how to use bridge networks instead.

Building a Product Assistant (Part 1: Understanding User Needs and MVP Specification)

After our achievement at GEMASTIK, we decided to capitalize on the momentum and compete in another competition. Our eyes are set on a global-scale hackathon organized by Docker on Devpost. This competition lasted a month from October to November 2023. The theme revolves around using AI to solve problems related to developer experience and productivity. After going through the process of finding and validating ideas, we decided to build a product assistant to help product and engineering go through the requirement gathering, scoping, understanding, and task delegation process. We went on to winning an honorable mention with this product. How did we do it?

Journey to GEMASTIK XVI

Since June and up to early September 2023, I've been working on a project for a competition. A nationwide IT and Communications competition held by the Ministry of Education and Culture between the best of the best teams from various universities in Indonesia known as GEMASTIK. My team (NextGen) and I participated in the Software Development division. We managed to take 4th place and received an Honorable Mention. While I am happy with our results, I would like to take the time to write about the events leading up to this and reflect on what I've gone through for the past few months of this year that has changed my life in more ways than one.