C++ curiosities: one does not simply move a const object

moveWhen I learned about the C++11 move semantics for the first time, it was mighty confusing to me. My mental model of moving something, as in “move a physical object from point A to point B”, was clearly not an adequate mental model for what C++11 calls “moving an object”. And one of the examples of this inadequacy is the case of const objects. You’d think that it’s perfectly normal to “move” something without changing it, right? I mean, you’re just taking a thing and putting it into another place. The thing itself stays the same!.. But no, to “move” an object in C++ you must be able to change it, because the moving works by breaking into the object, copying some of its internals, and rewiring what’s left in there to change the destruction behavior. Since this is sort of counter-intuitive, bad things can happen if you’re not being careful. I’m showing a couple of real-world examples below.

This post continues the move semantics series: std::move that doesn’t move; move semantics is not about moving; move semantics, sizeof, areaof, and pointy types.

Read the rest of this entry »

Rust syntax highlighter for Far Colorer

Published a minimal schema for Rust syntax highlighting for FarColorer.

Without the new schema, FarColorer plugin in Far Manager picks C++ syntax highlighter for Rust source code files, and while it does look somewhat “rusty”, it is difficult to read:

With the new schema:

  • Rust keywords are recognized;
  • comments are recognized (without nested syntax highlighting yet);
  • single apostrophe in “lifetime parameter” (?) doesn’t derail the parser.

C++ curiosities: move semantics, sizeof, areaof, and pointy types

This post continues the topic raised in “C++ curiosities: move semantics is not about moving”. Last time we’ve seen how a move operation can be split into 2 steps: “shallow copying” and “destructor disarmament”. This time I’ll show a way of using “areaof” to understand the benefits of move operations on a given type, and what I call “pointy types” in my mental model of move semantics.

Let’s start with sizeof and areaof. I’m sure you know operator sizeof, but I’m not sure everyone have seen the term areaof before, since it is not part of the standard C++. It’s kind of an intuitively simple concept, the total amount of memory owned through an instance of an object, but it doesn’t seem to have a well-established name. Have you heard it before?.. Anyway, so far I’ve only seen Alexander Stepanov using it consistently in his papers and talks. To paraphrase an example he gives in the “Notes on Programming” (p. 32), here is how one’d compute areaof for a vector<int>:

size_t areaof(const vector<int>& x)
   return sizeof(vector<int>) + x.size()*sizeof(int);

Read the rest of this entry »

Meta: dissecting yet another coder’s blog

In this post I share my blogging experience for those who are considering to start their own programming-related blog or who are just curious about what it takes to maintain a blog. Note that I’m focusing on software development blogs here, for other kinds of blogs my advice could be completely irrelevant.



My blog is WordPress-based, but before discussing the specifics of this particular platform, let’s look at some alternatives, which might be viable, depending on your goals and software development experience:

  1. You might want to create your blog and your website from scratch, using only the basic building blocks provided with a particular language. The disadvantage of this approach is that you might have to reimplement some basic blog features that you’d otherwise get for free with a WordPress plugin, but on the other hand, you might sometimes find an open-source library that will also give you that feature with little or no effort. The advantage is that you’d have full control over the website, and you might learn a lot just from the exercise, especially if you decide to use a new language or library for that project. My friend Ivan had recently rewritten his website engine from Java to Haskell and published an interesting blog post about his experience.
  2. You might want to look into website and blogging engines “for hackers”, such as Octopress, Jekyll, Hakyll, etc. I have to say that I like these projects in principle, because I like the idea of keeping blog posts in a repository under source control. However, last time I tried Octopress it couldn’t match all the functionality I’m used to in WordPress, so I didn’t switch. But it is definitely something to keep an eye on.
  3. You might want to use LiveJournal, or Blogger, or a similar service, but then you’d get a sub-domain URL, and the least amount of control over your data and blog configuration. Also you won’t be able to host anything else on your domain. This wouldn’t work for me, because I might eventually add other services under my domain, and in fact I’m already using it to host the AnnotateMe web-service, which produces dynamic annotated images, like the one below.

Read the rest of this entry »

Mini-update on flatbuffers-with-spirit

There’s not a whole lot of news about flatbuffers-with-spirit since the last time I blogged about it, but I’ve followed up on some todo-items:

  • I have filed a few bugs for CLion based on my experience;
  • I have restructured the project to move tests into a separate Biicode block from the implementation (so that now, for example, I can “publish” my implementation block and anyone else can depend on it via Biicode);
  • I have updated dependencies of the block so that Catch framework would be also downloaded from Biicode rather than being stored in repo as a header file;
  • I have updated the instructions on how to download and build the repo;
  • I have played with Boost.Karma to see if it will be a good fit for the task and set up a very simple generator.

Now I’m going to cover the new structure of the project in more detail and also summarize what I’ve learned.
Read the rest of this entry »

%d bloggers like this: