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.

read more

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;
    };
}

read more

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.

read more