GPT Code Review
2024-04-16
In my hobby and open source projects, I often work alone. This can result in becoming somewhat insulated while working in my own bubble. Some time ago, I began using a pull request workflow with self-review. This method has proven quite effective, though occasionally, minor oversights still slip through the cracks.
Recently, with the rise of large language models (LLMs) like ChatGPT, we have access to remarkable language understanding tools. I've now automated the process to submit a code review request for every pull request I make.
C++ Defer
2024-03-24
In the development of C++ applications, especially those interfacing with C-style APIs, managing resources efficiently while ensuring exception safety can be challenging. To address this, I wrote a Zig-inspired defer construct, offering a practical solution for scenarios where implementing a full RAII wrapper is deemed excessive.
The defer construct is designed as follows:
namespace stdex
{
class defer
{
public:
defer(const std::function<void ()>& fun) noexcept
: fun(fun) {}
~defer()
{
if (fun)
{
fun();
}
}
void cancel() noexcept
{
fun = {};
}
private:
std::function<void ()> fun;
defer(const defer&) = delete;
defer& operator = (const defer&) = delete;
};
}
Github Self Review
2022-11-12
Git and github have developed the well known pull request workflow. In that the master branch is only pulled and any code changes are brought back through a pull request that will be approved by a contributor or colleague. Part of the pull request workflow also contains automated checks, such as building the software, running unit tests or static code analysis. This has become the first line of defense for code quality and an industry standard procedure.
The code review process also has an interesting tenagential benefit. Because you will be presenting your code to someone else, you want to ensure a consistent scope. This makes sure that each commit actually contains one change and this forces you to think through and plan your code changes.
Efficient Standup Meetings
2022-08-29
All modern and agile organizations have them, stand-up or daily meetings. They are a short daily sync, generally in the morning, that make sure every team member is up to speed on what everybody is doing.
The use of the stand-up is to pick up slack and make sure that certain vital information is communicated. To be honest a functional team would not need this kind of meeting, since all this info would be shared over a coffee or at the water cooler. But even the best teams make sure that the stand-up is observed, since break down in communication can be a risky and expensive situation.
"Stand up meeting" by Ben Terrett is licensed under CC BY-NC-ND 2.0 .
Getting Rid of the Consent Popup.
2021-12-08
How do you get rid of the consent popup?
Simple, don't use cookies or store the users data. As simple as this sounds, unfortunatly this is not as simple to implement.
Before we get into the details, let's look at why we needed a consent popup in the first place. There are basically 3 pieces of legislation of interest:
- European Union's ePrivacy Directive
- European Union's General Data Protection Regulation
- California Consumer Privacy Act
Although there exist more laws and directives, these are the most stringent laws around online privacy. So as a rule of thumb if you comply with these laws, you comply with all other weaker laws. Without going into to much detail, the gist of the laws is, before you collect data about your users and hand it of to third parties, you need to get explicit and informed consent for doing so.
But I have a static blog, I am not collecting any data, right? I don't need a cookie and privacy banner.
Masks
2020-04-26
DISCLAIMER: The information given in this post is a best effort attempt at making my family safe and spreading useful information, i am just an engineer.
Let's talk about masks.
Lets talk about you and me,
Let's talk about all the good and bad things that may be,
Let's talks about masks.
Ok, that was a bit tortured, but masks are important, even for the general population. You may have heard that makes have no significant effect in preventing, virus spread and that is not entirely wrong.
Many well founded scientific opinions can be found, one that I kept coming across was COMMENTARY: Masks-for-all for COVID-19 not based on sound data, which asserts, that
In sum, given the paucity of information about their performance as source control in real-world settings, along with the extremely low efficiency of cloth masks as filters and their poor fit, there is no evidence to support their use by the public or healthcare workers to control the emission of particles from the wearer.
Which is a reasonable assumptions about cloth masks in a health care setting. But this assertion is extended to the use of masks in the general populace with the added caveat
Leaving aside the fact that they are ineffective, telling the public to wear cloth or surgical masks could be interpreted by some to mean that people are safe to stop isolating at home.
At least in Germany, the mask carrying laws still emphasize social distancing and go only in effect in situations where the 1.5m distance rule can not easily be applied, such as in public transportation and during shopping.
Immutable Containers and Thread Safety
2020-03-07
I have been using immutable.js recently and in the context of JavaScript it makes a lot of sense. The problem I am trying to solve with immutable.js is the aliasing problem. That is, I get a list of widgets from somewhere and I need to alter the list before I can display it. Doing this in-place is not a good idea, because this may break some other code that holds onto the list.
I like this programming idiom so much that I am seriously considering mplementing it in C++. While I am tinkering with my C++ experimental code and my research I keep coming across the assertion that immutable objects are thread safe. The original presentation or this rather nice article mention it as if it was an immutable truth.
But they are just wrong. It is true that with the right use of atomics you can create immutable containers that will not have memory races or crash, but that does not make them functionally correct.
Take a well known example from multi-threading programming, the humble bank account. In our case we will represent the bank account as an immutable ledger of all transactions that occurred. All you can do to the ledger is add transactions, so the naive implementation would be as follows:
class Account
{
public:
void append(const Transaction& transaction)
{
ledger = ledger.push_back(transaction);
}
private:
i7e::imutable_list<Transaction> ledger;
};
C++ Signals
2020-02-15
While working on one of my current hobby projects I needed to broadcast a state change to more than just one observer. I was quick to add my rather trusted EventEmitter. But I did hesitate, because something about the EventEmitter always bothered me.
The problem with EventEmitter is that, although EventEmitter is type safe, the type safety can only be asserted during runtime. A bit like JavaScript, where it comes from, assigning wrong typed handlers will throw an exception when the caller is actually called.
enum
{
FOO_EVENT
};
EventEmitter emitter;
emitter.on(FOO_EVENT, [] (int c) {
// do something
});
long change_value = 42;
emitter.emit(FOO_EVENT, change_value); // exception
This was always annoying, since there are so many different types that are effectively the same, but the compiler really things are different. For example, the types size_t, int and long can be the same type, and yet the compiler thinks they are not.
Modern Propaganda
2019-06-20
I recently got into an argument, by clamming that the new HBO mini series Chernobyl was modern propaganda. The counter was, I could not evaluate this since I had not yet seen it. The series seems really interesting and well made, and I just have not yet found a legal way to watch it in Germany. But I assert, that this dramatized not quite documentary is propaganda, even if they remain true to the real events and facts. I give Chernobyl the benefit of the doubt, even though I have grounds to believe that they got some facts wrong.
The Second 90%
2018-01-02
A few years back I read a long lost article for indy game devs, that you should:
"Take your worst case estimate, double it and use that as your best case estimate."
This puts it mildly, but humans are for the most part really bad at estimating effort.
The standard project management aproach to managing large tasks with a high degree of uncertainty is to break down the large task into smaller and smaller tasks. The idea is that each task can be reasoned about and thus estimated to a higher degree of certainty. This is true, but...
In many project management software, you can show single task progress in percent. Unfortunately, almost all tasks in progress are pegged at 90% and the software will helpfully show nice charts. But this is misleading, since a task that is not done, is not done. A task has exactly 3 relevant states:
- not started
- in progress
- done