Posted on 4th of May 2024
| 390 words
Some months ago I decided to join back to social media in the form of
registering to Mastodon.
I thought that maybe this
could be the platform to fill the void – which I’ve later realised to be
non-existent – of social medias in my life. But now I’ve decided to leave it as
well. Not necessarily due to same reasons why I left social medias like
Facebook, Instagram or Twitter. But still, partly due to same reasons.
One of the main reasons why I left mainstream social media platforms was their
draconian behaviour behind the scenes. Addictive design principles behind their
applications, algorithms promoting content that you didn’t ask for, data mining
and profiling, and so on. Fortunately, in Mastodon, these sort of issues weren’t
present, which was one of the reasons why it felt so welcoming. It had this
weird old internet type of aura in it. Like being part of this weird digital
clique.
Also, just from the pure technological point of view, the federated elements of
Mastodon – or ActivityPub in general – seemed quite interesting. Finally, a
platform competing with the centralized behemoths where users were able to
retain control over the data and interaction without being riddled with
profit-driven algorithms. If I would want to be part of some social media, it
still would be Mastodon, which might sound slightly odd considering the title of
this post.
So why did I then decide to leave it? One of the main reasons why I didn’t enjoy
using e.g. other mainstream social medias, was the fact how they started affect
my own behaviour. The constant urge to check what’s going on. Picking up your
phone, opening the app, or just going to the site itself out of habit without
necessarily even having a reason for it. It is addicting. It is meant to be
addicting. Although, in Mastodon’s case, probably not maliciously.
So while I thought investing time and energy into building connections and
contributing to various discussions in Mastodon would be beneficial, and no
doubt, they can be. For me, it just started feel like sacrificing my mental
well-being for digital engagement, again.
Mastodon is by no means a bad platform. It just isn’t suitable for me who wants
to navigate digital landscape mindfully and intentionally without being ensnared
into various addictive grasps once more.
Posted on 30th of April 2024
| 498 words
Haven’t written one of these in couple of months since I’ve mainly spent my time
reading various papers - mainly computer science related - and not so much
literature, but I finally got back to the saddle so here’s the latest reviews.
William Strunk Jr.: The Elements of Style (reread)
English is not my native language – even though I mainly write in it for this
site – so grammatical and other style rulings when it comes to writing is
something that I always struggle. While I would consider these rules to be
relatively easy, I tend to always forgot them since they’re still so different
from the rules of my native language, Finnish.
The Elements of Style is a short book is comprised of these sort of elementary
rules for writing English. Due to the length of this book, I have read this
many times and every once in a while, I tend to come back to it. It was quite
a useful read for me since I have had a few month break from writing
altogether so it was beneficial for waking the old habit.
Kimmo Svinhufvud: Kokonaisvaltainen kirjoittaminen (reread)
On similar theme as above, this focuses mainly on writing style in Finnish.
Stephen King: On Writing: A Memoir of the Craft
This book has been on my reading list for some time just out of sheer
curiosity. I’ve always enjoyed Stephen King’s writing and I know how
proficient he is at writing. Especially considering how much he publishes
yearly. On Writing: A Memoir of the Craft is a wonderful book that gives a
glimpse to the life of writer and how one becomes one.
Writing has always interested me, and especially lives of remarkable writers.
What sort of life events might’ve affected their style and stories. So it’s
wonderful to hear such life stories written by the writer themselves.
Andrew Appel: Modern Compiler Implementation in ML (reread)
If you’ve followed my blog, I have spent some of my free time hacking my own
programming language and compiler. Appel’s book on implementing compiler has
been a standard that every once in a while I tend to go back to refresh some
memories. Wonderful book.
George Saunders: Lincoln in the Bardo
I’ve been a big fan of George Saunders’ works for long time, especially his
short stories. Lincoln in the Bardo was his first novel released in 2017 and I
have had it on my reading list for a long time and I finally got into reading
it. Thankfully I did so since it was such a pleasurable read.
Novel tells the story of aftermath of passing of Lincoln’s side and it was
written in quite weird style. The style the novel was written is might
definitely not so easily approachable for every reader and it started like
that for me as well. Once you get into it, it start to open up. Definitely
well written – even despite the unusual style – and worth a read.
Posted on 2nd of April 2024
| 550 words
In the domain of C++ optimization, we encounter two key players: Return Value
Optimization (RVO) and Named Return Value Optimization (NRVO). These techniques
excel in simplifying function returns by avoiding unnecessary object copies or
moves, akin to a direct transfer from temporary to destination.
Looking at the example:
class Object {
public:
Object() { std::cout << "Construct at " << this << "\n"; };
~Object() { std::cout << "Destruct at " << this << "\n"; };
Object(const Object &) { std::cout << "Const Copy at " << this << "\n"; };
Object(Object &&) { std::cout << "Move at " << this << "\n"; };
Object &operator=(const Object &) {
std::cout << "Const Copy Assignment at " << this << "\n";
return *this;
};
Object &operator=(Object &&) {
std::cout << "Move Assignment at " << this << "\n";
return *this;
};
};
Object TestRVO() { return Object{}; }
Object TestNRVO() {
Object obj;
return obj;
}
Object obj = TestRVO();
Object obj2 = TestNRVO();
Since C++17, Return Value Optimization (RVO) has been governed, and the moment
when a constructor is invoked is termed “materialization”. C++17 specifies that
materialization should be delayed as much as possible, typically until it binds
to references or until a class’s member is accessed using the dot operator, or
until an array is subscripted using square brackets or converted to a pointer.
Alternatively, materialization occurs when the value is ultimately discarded,
ensuring that at least one temporary is created. On the other hand, Named Return
Value Optimization (NRVO) lacks regulation but is commonly implemented by
proficient compilers.
RVO and NRVO can be disabled under certain circumstances, such as conditional
returns (if(xx) return x; else return y;)
, returning a function parameter or
global variable instead of a local variable, or returning a non-id-expression.
This explains why using std::move(id)
is discouraged when NRVO is available.
In scenarios where RVO/NRVO is applicable, no move operations are triggered.
Conversely, in their absence, move operations become inevitable. Another
optimization step occurs where the compiler attempts to interpret an
id-expression as an xvalue. Consequently, return x;
is equivalent to
return std::move(x);
, obviating the need for copying.
For example:
struct S {
S() = default;
S(const S &) = delete;
S(S &&) { std::cout << "here;"; };
~S() = default;
};
// NRVO happens, no move at all.
S foo() {
S s;
return s;
}
// BAD, NRVO can happen, but it's disabled, so move ctor is called.
S bar() {
S s;
return std::move(s);
}
// NRVO is disabled due to conditional return; however, the subsequent
// optimization ensures no unnecessary copy is made.
S foofoo(bool use) {
S obj1, obj2;
if (use)
return obj1;
return obj2;
}
// Similar to the previous function, but redundant std::move calls are added
// unnecessarily.
S barbar(bool use) {
S obj1, obj2;
if (use)
return std::move(obj1);
return std::move(obj2);
}
When NRVO and RVO optimizations fail, a copy operation ensues. In such cases,
manual move operations are required if moving is preferred. Note that t.s
isn’t
considered an id-expression, hence both optimizations fail, necessitating
explicit move calls like std::move(t.s)
or std::move(t).s
.
The subsequent optimization, officially known as implicit move, is a feature
anticipated in C++23. Before its introduction, implicit moves are subject to
stricter constraints compared to id-expressions.
Complexity of C++ never ceases to amaze me.
Posted on 31st of March 2024
| 183 words
So, again, I’ve been in this annoying procrastination rut when it comes to my
writing (literature and coding) and reading. I’ve been quite active in other
interests although, especially music, since I just recently had one gig after a
long break of not gigging and it was super fun! But now, I’ve felt the urge to
get back to books and programming, while still of course trying to keep musical
activities relatively active.
I’ve started to read through couple new tech books focusing on compilers and
garbage collection and also rereading some German literature classics, mainly
for trying to learn the language. Also, I should get back to
Sila
development at the same time. Next
steps for the Sila development is probably going to be to start working with
code generation for aarch64. This is due to the fact that I recently got a new
Macbook with ARM processor (M3 Max), so now I need to start worry about code
generation for both x86-64 and aarch64. Which is probably going to be quite a
lot of work but hey… it’s fun (I hope).
Posted on 2nd of February 2024
| 611 words
Somebody contacted me and mentioned that there is something off with my RSS
feeds, thanks for that. I don’t know what had happened and when, but for some
reason my normal RSS link.
Didn’t contain the correct
information. It seemed to only contain the summary of the post. I recently did
some overhaul in my own Hugo theme and its layouts so most likely I had put
something to wrong place while doing that causing this.
When I started looking at what Hugo generated, it seemed that the correct feed
was actually located at the root of my site, so topikettunen.com/feed.xml
but this isn’t right. I remember making it so at one point that I only
generate the feed in the blog section since - personally speaking - I don’t
really see the benefit of generating the feed elsewhere.
This seemed to be caused by error in my Hugo configs, which most likely I had
accidentally changed at some point. I had to add the following to my
config.toml
:
[outputs]
home = ["HTML"]
section = ["HTML", "RSS"]
taxonomy = ["HTML"]
This makes it so that Hugo generates only HTML when it comes to home and
taxonomy page (so archive
and tag
for me). In section,
like blog
, it’ll generate HTML and RSS. So that was fixed.
Like I mentioned above, the RSS feed generated under section was still wrong
since it only contained the summary. In my Hugo theme, I had already created a
custom layouts/index.rss.xml
in there with the change:
-<description>{{ .Summary | html }}</description>
+<description>{{ .Content | safeHTML }}</description>
So that it’ll generate the whole content in there instead of summary, which
Hugo does by default. Unfortunately, this was one was in the wrong place for
section RSS. It should be in layouts/section/section.rss.xml
, and then it
works fine!
Also having full content under description
in the RSS XML seems quite odd so
I fixed it to look like:
<description>{{ .Summary | html }}</description>
<content:encoded>{{ .Content | html }}</content:encoded>
To have both in their own correct fields.
I also noticed that my custom notice shortcode looked quite ugly in the RSS
feed. You might’ve seen these notices e.g. when reading my Sila dev
log.
The way I had done this
shortcode was the having the following in layouts/shortcodes/notice.html
:
<table class="notice">
<tbody>
<tr>
<td>
{{ .Inner }}
</td>
</tr>
</tbody>
</table>
I know, this probably could be done with something else than table, but hey,
I’m not a designer.
Which I then would call in my Markdown files like:
{{< notice >}}
<strong>Plug</strong>: <a href="https://github.com/topikettunen/sila" target="_blank">Follow the Sila development here.</a>
{{< /notice >}}
Also while writing this, I learned how to escape shortcodes in Hugo in case
you want to use them in write them in your Markdown, but not actually use
them. You need wrap the short code inside {{</* notice */>}}
.
But unfortunately it would just generate that in the beginning of the RSS
content without proper HTML tags etc. So instead of using the notice as a
shortcode, I removed the shortcodes from Markdown and just added the following
to my layouts/_default/single.html
:
{{ if in .Params.tag "sila"}}
<table class="notice">
<tbody>
<tr>
<td>
<strong>Plug</strong>: <a href="https://github.com/topikettunen/sila" target="_blank">Follow the Sila development here.</a>
</td>
</tr>
</tbody>
</table>
{{ end }}
This only works when blog has a tag sila
in it. Of course, if I would like
to use such a notice in some other posts, this wouldn’t work, but for now,
it’s good enough for me. This way also Hugo doesn’t include the notice in the
generated RSS, making the feed look little bit neater!
But hey, at least now the RSS feed should be working how it should!