Whither, elegant C++?

A project log for Low power mesh networking for small sensor grids

Tiny MQTT-interoperable broadcast mesh networking with simple radios

DanielDaniel 06/10/2017 at 03:570 Comments

This project is written in embedded C++11, using prepackaged algorithms to build an efficient key/value store with a pleasingly small amount of code. Frustratingly I know how to write working C++ but I don't know how to make it beautiful, with brute force stacking of pointers, parens and references everywhere to coax the necessary type out of each expression, until the compiler is happy.

auto element = reinterpret_cast<Contained *>(malloc(packet->len));
trickle_timer_reset(&(element->trickle), time_now);
memcpy(&(element->payload), packet, packet->len);
consistent(&((*existing)->payload), packet);

My point of comparison is the stm32plus library, mostly templates, which makes the stm32 much easier to program. Sure, you may have to stare at it for an hour to figure out how the recursive variadic template inherits from itself but it is written with a purpose and clarity that I have yet to find in my own C++.

I usually program in Python but I love the completely different challenge of programming for these tiny microcontrollers where every byte matters.