# PIMPL idiom in C++

Developers working on a “software library” in C++ (or any other native language) should follow a set of critically important rules, or their customers will soon be in trouble using their product. Some of these rules are for example Semantic Versioning, Good API Design and Keeping Backward Compatibility. The later one has many aspects and requires its detailed post. In this post, I will discuss one of the vastly used techniques in C++ which helps developers to keep Backward Compatibility in binary (ABI) level.

# Pure Functions in C++‬

One of the best optimisation features of C++ is declaring functions as pure. This one is less known to developers, though it can be an excellent optimisation hit for your software. Marking a function with “pure” attribute enables a wide range of possible optimisations for the compiler. You must declare your pure functions as such, in all code that cares about performance. In this post, I am going to show how to use this feature and its effects on generated code.

# English Blog!

So I started to translate my old Persian content into English, as an exercise (well, mostly out of bordem duo to COVID-19 lockdown…). I’ll keep dates intact. I hope you’ll find it interesting…

# Non-Gregorian Calendar Systems in Qt

For Iranian general public, working with date and time in a computer system has always been challenging. As opposed to - almost - entire population of the planet, we use a different calendar system (actually a better one!) but computer systems are not designed and developed with non-Gregorian calendaring in mind. So we always have to use unconventional methods and hacks to provide functionality of the official calendar of the country - Solar Hijri…

Personally, for me the absence of the Solar Hijri calendar in Qt has always been annoying. Whenever I wanted to work with date and time in my C++ GUI applications, I had two options: Either use my own custom widgets (which where not as good as Qt’s widgets), or simply use the Gregorian calendar (which is annoying for the final user).

Since version 4.6, right after I released Persian translation of Qt, I was thinking of implementing the solar calendar for this framework. Unfortunately, in that time it was not possible to implement it for many reasons. However, I made some prototypes, but it did not make it to Qt5. Qt5 had its own sad story, with the premature release of version 5.0; the opportunity created by changing the major version was also missed. Though finally, after 6 years and forgetting all about calendars, I had the chance to implement the solar Hijri calendar for Qt 5.10. The final version has been released with Qt 5.14 on December 12, 2019. This post describes challenges, and the process of the work, and also the API itself.

# Mathematical Constants in C++

None of C++ standards has defined π number. So every programmer who needs to do some math including, for example, trigonomerty or statistics, has to define π herself. Luckily header files have defined π (See M_PI in math.h). Though it is not ultimately safe and portable to use these constants. It might casue numeric errors in critical applications. In this blog post, I am going to show a better way to reach a safe π.

# Worst Ever Qt Bug (for me!)

I think Qt is one of the best software development frameworks. It has a nice GUI library alongside with many other tools, provided as a neat and clean API. KDE desktop environment is almost entirely based on Qt framework. I’ve been using it for a decade now, and I have successfully delivered dozens of projects – both embedded and desktop – most of them only using Qt. Though starting from version 5.3, a tiny bug has appeared in the core library, that makes life difficult for me: It is impossible to insert invisible characters in Qt’s text engine. That is you can’t type ZWNJ, ZWJ, LRE, RLE and PDF characters. (I have described what they in this post: Control Charachters and Bi-Directional Text. The effect of this bug is so huge that makes it impossible for me to use KDE or any other application that uses Qt. To see how it didn’t work for us, imagine being unable to type, for example, “space” character in any application on your operating system! In this post I am going to show a workaround and explain how to fix this bug. It is already fixed in recent versions of Qt, though it is not in official repositories yet. Fortunately, the workaround is very simple and does not break anything. Finally I’ll provide a patch for 5.9. Hope this helps someone.