#tuesdaycodingtips
Tip 96 of #tuesdaycodingtips - Reference equality in C#

Languages other than C++ are also prone to having "fun" footguns. Take C#'s reference semantics for example. All I wanted was a dictionary with a file hash as a key. Since built-in cryptographic tools […]

[Original post on techhub.social]
April 21, 2026 at 10:56 AM
Tip 95 of #tuesdaycodingtips - Copy & swap idiom

Rule of 5 says that if you need to implement one of the copy/move constructors/assignment operators or a destructor, you shall implement all of them to avoid resource management issues. However, this often […]

[Original post on techhub.social]
March 24, 2026 at 11:22 AM
Tip 94 of hashtag#TuesdayCodingTips - C# Disposable pattern

Disposable pattern is an attempt to retrofit scope-based resource management into a garbage-collected language. It executes a dedicated cleanup function when the object goes out of scope, rather than […]

[Original post on techhub.social]
March 10, 2026 at 11:08 AM
Tip 93 of #tuesdaycodingtips - Constrained auto

Tired of convoluted templates in your C++? Want to make them more legible?

C++20 introduced concepts - a powerful feature that can restrict your templated APIs to only such arguments that fulfil a particular […]

[Original post on techhub.social]
February 24, 2026 at 11:16 AM
Tip 92 of #tuesdaycodingtips - Pinning interop memory in C#

When interoping C# with, for example, C++, one can send a pointer to the managed memory directly to the native code and work with it without the need to copy it into the local address space. For as […]

[Original post on techhub.social]
September 23, 2025 at 10:40 AM
Tip 91 of #tuesdaycodingtips - String or StringBuilder?

If you're a C++ programmer, you can easily troll yourself while working with C#'s `string` objects. In C++, they are optimized vectors of bytes and can be dynamically resized at will through […]

[Original post on techhub.social]
September 2, 2025 at 1:53 PM
Tip 90 of #tuesdaycodingtips - Is enum value defined?

In both C++ and C#, enums are mere named numerical constants. Even if they appear to be distinct types, and switch statements can check whether you covered all names within an enum, that's simply not […]

[Original post on techhub.social]
August 19, 2025 at 1:25 PM
Tip 89 of #tuesdaycodingtips - Semantic versioning

When creating a library, semantic versioning is a really useful versioning scheme to use.

It's a promise to your users that changes bumping the minor/patch version numbers are backward-compatible. As such, much of the software relies on these […]
Original post on techhub.social
techhub.social
July 8, 2025 at 12:59 PM
Tip 88 of #tuesdaycodingtips - Enum-discriminated unions with nlohmann::json

JSON is a fairly trivial format and as such, its only way of supporting polymorphic data is an enum-discriminated approach.

In other words, you might have an array of objects where […]

[Original post on techhub.social]
June 24, 2025 at 10:14 AM
They say learning by example is the best way to learn. I'd like to share one such example of API design process based on a recent discussion with one of my colleagues: https://medium.com/@nerudaj/a-case-study-on-api-design-f22a8665cf2d

If you follow my #tuesdaycodingtips, this showcases a […]
Original post on techhub.social
techhub.social
June 12, 2025 at 11:06 AM
Tip 87 of #tuesdaycodingtips - Emplace into a vector of variants

`emplace_*` is an alternative to methods like `insert` or `push_*` in standard C++ containers. It allows you to construct the inserted object directly inside the container, passing all required […]

[Original post on techhub.social]
June 3, 2025 at 10:18 AM
Tip 86 of #tuesdaycodingtips - Extendable logger pattern

I like my logs structured. If nothing else, I can log into a CSV file, load that CSV into Excel, turn on filters, and boom, I have a quite nice log analyzer tool. To get the maximum out of it, I need to […]

[Original post on techhub.social]
May 20, 2025 at 11:02 AM
Tip 85 of #tuesdaycodingtips - Incomplete types and name demangling

While writing type-safe APIs, a "tag" type is often useful. It is nothing more than a forward declaration of a type that will never be fully defined, just for the sake of creating a template […]

[Original post on techhub.social]
May 6, 2025 at 10:16 AM
Tip 84 of #tuesdaycodingtips - C++ type trait for callable types

I recently asked myself: How do you make a reliable type trait for callable types so you can read their return values and call parameters?

The complexity lies in the fact that C++ has four […]

[Original post on techhub.social]
April 29, 2025 at 10:09 AM
Tip XX of #tuesdaycodingtips - Curious case of NLOHMANN_JSON_SERIALIZE_ENUM

I recently debugged a case where code generated by NLOHMANN_JSON_SERIALIZE_ENUM failed at invariant assertions deep in the nlohmann_json library. When examined under a debugger, the […]

[Original post on techhub.social]
April 8, 2025 at 12:47 PM
Tip 82 of #tuesdaycodingtips - C# exception filter

Ever found yourself in the situation where you have an exact same handling code for two (or more) selected exception types? C# has a nice way of deduplicating said code.

A `catch` block, processing a base […]

[Original post on techhub.social]
April 1, 2025 at 10:35 AM
Tip 81 of #tuesdaycodingtips - Pattern matching a C++ enum

For a particular C++ application I wrote, I wanted to send an enum over a string-based protocol and pattern match on it on the receiving end to make sure that all possible values were handled.

You […]

[Original post on techhub.social]
March 4, 2025 at 12:44 PM
Tip 80 of #tuesdaycodingtips - C# lambdas and mutability rules

Mutability rules in C# are funky. While trivial types are passed into functions by value, they are captured by reference for their usage in lambdas.

That can lead to stupid bugs - what if you […]

[Original post on techhub.social]
February 18, 2025 at 11:47 AM
Tip 79 of hashtag#TuesdayCodingTips - Many ways of collecting values from a map

How can you collect values from a std::map into some collection in C++? I know three basic ways to do so.

➤ A naïve imperative approach is manually iterating over the map and […]

[Original post on techhub.social]
February 11, 2025 at 12:15 PM
Tip 78 of #tuesdaycodingtips - Many ways to read a file in C++

In C#, you can easily read a whole file using `File.ReadAllText` method. Obviously, things can't be as easy in C++.

You can choose the 'old way' where you pre-allocate a buffer to which you can […]

[Original post on techhub.social]
January 28, 2025 at 12:12 PM
Tip 77 of #tuesdaycodingtips - Multidimensional subscript operator

A quality-of-life C++23 feature has finally been integrated into Visual Studio (v17.12) after it was available in Clang (trunk) for quite some time. That feature is the support of the […]

[Original post on techhub.social]
January 14, 2025 at 12:12 PM