<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>As told by Matt</title><link>https://rodusek.com/</link><description>Recent content on As told by Matt</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>©2020-2024 Matthew Rodusek.</copyright><lastBuildDate>Sat, 14 Dec 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://rodusek.com/index.xml" rel="self" type="application/rss+xml"/><item><title>Go Tip: Creating Closed Interfaces</title><link>https://rodusek.com/posts/2024/12/14/go-tip-creating-closed-interfaces/</link><pubDate>Sat, 14 Dec 2024 00:00:00 +0000</pubDate><guid>https://rodusek.com/posts/2024/12/14/go-tip-creating-closed-interfaces/</guid><description>&lt;p>In &lt;a class="language link" href="https://rodusek.com/languages#go">go&lt;/a>
, interfaces are satisfied by any type that implements all of the
methods defined in the interface. This makes Go interfaces &amp;ldquo;open&amp;rdquo; types, meaning
that any type can satisfy an interface at any time.&lt;/p>
&lt;p>However, did you know that Go actually has a mechanism for restricting who can
implement these types? This &lt;a class="category link" href="https://rodusek.com/categories/#go-tip">go-tip&lt;/a>
will tell you how you can
accomplish this.&lt;/p></description></item><item><title>Blog Reboot</title><link>https://rodusek.com/posts/2024/01/02/blog-reboot/</link><pubDate>Tue, 02 Jan 2024 23:47:29 +0000</pubDate><guid>https://rodusek.com/posts/2024/01/02/blog-reboot/</guid><description>&lt;p>It&amp;rsquo;s been a &lt;em>long&lt;/em> time since I&amp;rsquo;ve last updated this blog &amp;ndash; and I think I&amp;rsquo;m
finally ready to reboot it.&lt;/p>
&lt;p>A lot has changed since my last article nearly 3 years ago:&lt;/p>
&lt;ul>
&lt;li>I changed jobs a number of times, and am now begrudgingly working as a &lt;a href="https://go.dev"class="markdown-link"target="_blank" rel="noopener noreferrer">Go&lt;/a>
developer professionally.&lt;/li>
&lt;li>I found new love of the &lt;a href="https://www.rust-lang.org/"class="markdown-link"target="_blank" rel="noopener noreferrer">Rust&lt;/a>
programming language and started writing rust
projects in my spare time.&lt;/li>
&lt;li>I&amp;rsquo;ve learned a lot about working in domains ranging from &lt;a href="https://cloud.google.com/"class="markdown-link"target="_blank" rel="noopener noreferrer">GCP&lt;/a>
to working
embedded on &lt;a href="https://www.ti.com/microcontrollers-mcus-processors/arm-based-processors/overview.html"class="markdown-link"target="_blank" rel="noopener noreferrer">Texas Instruments SoCs&lt;/a>
.&lt;/li>
&lt;li>I haven&amp;rsquo;t written any practical C++ in nearly a year.&lt;/li>
&lt;/ul>
&lt;p>I have a lot to talk about, and hope to use this blog as somewhere I can share
my knowledge and experiences with others that hope to learn and grow from them.&lt;/p></description></item><item><title>Reflecting Over Members of an Aggregate</title><link>https://rodusek.com/posts/2021/03/21/reflecting-over-members-of-an-aggregate/</link><pubDate>Sun, 21 Mar 2021 11:31:40 -0400</pubDate><guid>https://rodusek.com/posts/2021/03/21/reflecting-over-members-of-an-aggregate/</guid><description>&lt;p>A little while back a friend of mine and I were talking about serialization of
&lt;code>struct&lt;/code> objects as raw bytes. He was working with generated objects that contain
padding, but the objects needed to be serialized &lt;em>without&lt;/em> the padding; for
example:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl">&lt;span class="k">struct&lt;/span> &lt;span class="nc">Foo&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">char&lt;/span> &lt;span class="n">data0&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// 3 bytes padding here
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="kt">int&lt;/span> &lt;span class="n">data1&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">};&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>In the case he described, there are dozens of object types that need to be
serialized, and all are:&lt;/p>
&lt;ul>
&lt;li>Generated by his organization (so they can&amp;rsquo;t be modified), and&lt;/li>
&lt;li>Are guaranteed to be &lt;a href="https://en.cppreference.com/w/cpp/language/aggregate_initialization"class="markdown-link"target="_blank" rel="noopener noreferrer">aggregates&lt;/a>
&lt;/li>
&lt;/ul>
&lt;p>Being a template meta-programmer, I thought it would be a fun challenge to try
to solve this in a generic way using &lt;a class="language link" href="https://rodusek.com/languages#c&amp;#43;&amp;#43;17">c&amp;#43;&amp;#43;17&lt;/a>
&amp;ndash; and in the process I
accidentally discovered a generic solution for iterating all members of
&lt;strong>any aggregate type&lt;/strong>.&lt;/p></description></item><item><title>Getting an Unmangled Type Name at Compile Time</title><link>https://rodusek.com/posts/2021/03/09/getting-an-unmangled-type-name-at-compile-time/</link><pubDate>Tue, 09 Mar 2021 19:21:59 -0500</pubDate><guid>https://rodusek.com/posts/2021/03/09/getting-an-unmangled-type-name-at-compile-time/</guid><description>&lt;p>Getting the name of a type in C++ is a hassle. For something that should be
trivially known by the compiler at compile-time, the closest thing we have to
getting the type in a &lt;strong>cross-platform&lt;/strong> way is to use
&lt;a href="https://en.cppreference.com/w/cpp/types/type_info/name"class="markdown-link"target="_blank" rel="noopener noreferrer">&lt;code>std::type_info::name&lt;/code>&lt;/a>
which
is neither at compile-time, nor is it guaranteed to be human-readable.&lt;/p>
&lt;p>In fact, both GCC and Clang actually return the compiler&amp;rsquo;s &lt;strong>mangled&lt;/strong> name
rather than the human-readable name we are used to. Let&amp;rsquo;s try to make something
better using the modern utilities from &lt;a class="language link" href="https://rodusek.com/languages#c&amp;#43;&amp;#43;17">c&amp;#43;&amp;#43;17&lt;/a>
and a little creative problem
solving!&lt;/p></description></item><item><title>Builder Pattern: Expressing ownership transfer</title><link>https://rodusek.com/posts/2021/03/02/builder-pattern-expressing-ownership-transfer/</link><pubDate>Tue, 02 Mar 2021 17:06:40 -0500</pubDate><guid>https://rodusek.com/posts/2021/03/02/builder-pattern-expressing-ownership-transfer/</guid><description>&lt;p>The Builder pattern is a common design in software development for late-binding
inputs to allow for iterative construction. This pattern, when applied in &lt;code>c++&lt;/code>,
leaves one very obvious question: &lt;strong>Can we present this to consumers in an
optimal way?&lt;/strong>&lt;/p>
&lt;p>More specifically: when we call &lt;code>build()&lt;/code>, should we be moving any temporary
internal state, or copy it? Can we express both in a safe and idiomatic way to
consumers?&lt;/p></description></item><item><title>Final Poetry</title><link>https://rodusek.com/posts/2021/02/28/final-poetry/</link><pubDate>Sun, 28 Feb 2021 01:23:18 -0500</pubDate><guid>https://rodusek.com/posts/2021/02/28/final-poetry/</guid><description>Note The C++WTF segment shines a light on the dark and esoteric corners of the C++ language for fun and profit The C++ standards committee is very strongly against producing any kind of breaking changes when considering new language features &amp;ndash; especially keywords. Over the course of standardization, this has lead to terms like auto being repurposed, or awkward keywords like co_await and co_yield being introduced in C++20 to avoid breaking a handful of projects in the world that might possibly be using await or yield in their vocabulary.</description></item><item><title>Creating a Fast and Efficient Delegate Type (Part 3)</title><link>https://rodusek.com/posts/2021/02/26/creating-a-fast-and-efficient-delegate-type-part-3/</link><pubDate>Fri, 26 Feb 2021 22:19:51 -0500</pubDate><guid>https://rodusek.com/posts/2021/02/26/creating-a-fast-and-efficient-delegate-type-part-3/</guid><description>&lt;aside class="alert alert-note" role="alert">
&lt;header class="alert-header">
&lt;p class="alert-title">
&lt;svg class="alert-icon" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true">&lt;path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z">&lt;/path>&lt;/svg>
Note
&lt;/p>
&lt;/header>
&lt;div class="alert-message">This is part 3 of a 3 part series.&lt;/div>
&lt;/aside>
&lt;p>In the &lt;a href="https://rodusek.com/posts/2021-02-26/creating-a-fast-and-efficient-delegate-type-2">previous post&lt;/a>
we updated our &lt;code>Delegate&lt;/code> object that we&amp;rsquo;ve been working on since
&lt;a href="https://rodusek.com/posts/2021-02-24/creating-a-fast-and-efficient-delegate-type">the first post&lt;/a>
to support covariance.&lt;/p>
&lt;p>In this post, we will look at how to make this a true &lt;strong>zero-overhead&lt;/strong> utility&lt;/p></description></item><item><title>Creating a Fast and Efficient Delegate Type (Part 2)</title><link>https://rodusek.com/posts/2021/02/26/creating-a-fast-and-efficient-delegate-type-part-2/</link><pubDate>Fri, 26 Feb 2021 22:18:32 -0500</pubDate><guid>https://rodusek.com/posts/2021/02/26/creating-a-fast-and-efficient-delegate-type-part-2/</guid><description>&lt;aside class="alert alert-note" role="alert">
&lt;header class="alert-header">
&lt;p class="alert-title">
&lt;svg class="alert-icon" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true">&lt;path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z">&lt;/path>&lt;/svg>
Note
&lt;/p>
&lt;/header>
&lt;div class="alert-message">This is part 2 of a 3 part series.&lt;/div>
&lt;/aside>
&lt;p>In the &lt;a href="https://rodusek.com/posts/2021-02-24/creating-a-fast-and-efficient-delegate-type">previous post&lt;/a>
,
we saw how we could build a simple and light-weight &lt;code>Delegate&lt;/code> type that binds
free functions, and member functions. However we have a notable limitation that
we require specifying the &lt;em>type&lt;/em> of the members being bound
(e.g. &lt;code>d.bind&amp;lt;Foo,&amp;amp;Foo::do_something&amp;gt;()&lt;/code>). Additionally, we&amp;rsquo;re forced to bind
only the &lt;em>exact&lt;/em> type. We can&amp;rsquo;t bind anything that is &lt;em>covariant&lt;/em> to it.&lt;/p>
&lt;p>Lets improve upon that.&lt;/p></description></item><item><title>Creating a Fast and Efficient Delegate Type (Part 1)</title><link>https://rodusek.com/posts/2021/02/24/creating-a-fast-and-efficient-delegate-type-part-1/</link><pubDate>Wed, 24 Feb 2021 20:03:14 -0500</pubDate><guid>https://rodusek.com/posts/2021/02/24/creating-a-fast-and-efficient-delegate-type-part-1/</guid><description>&lt;aside class="alert alert-note" role="alert">
&lt;header class="alert-header">
&lt;p class="alert-title">
&lt;svg class="alert-icon" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true">&lt;path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z">&lt;/path>&lt;/svg>
Note
&lt;/p>
&lt;/header>
&lt;div class="alert-message">This is part 1 of a 3 part series.&lt;/div>
&lt;/aside>
&lt;p>When working in C++ systems, a frequent design pattern that presents itself is
the need to bind and reuse functions in a type-erased way. Whether it&amp;rsquo;s
returning a callback from a function, or enabling support for binding listeners
to an event (such as through a &lt;code>signal&lt;/code> or observer pattern), this is a pattern
that can be found everywhere.&lt;/p></description></item></channel></rss>