C++ in 2017

michaelh@juju.net.nz 2016-06-25 https://juju.net.nz/michaelh/project/cxx17/

Overview

This project is to revisit C++ in 2017 and see how it compares to my recent experiences in Go.

Background

I’ve written significant amounts of code in C, ‘C with objects’ style C++, Python, and (recently) in Go. I quite like Go and especially the tooling around it, but miss things like generic containers from C++ and optional values (i.e. value or None) from Python.

Requirements

Find the state-of-the-art implementations of my favourite features from Go and Python and exercise them. These features are:

  • A fast build / run cycle
  • A package manager with a decentralised namespace
  • Unit tests with automatic discovery
  • Run-time inspection, especially being able to inspect a struct for fields.
  • A light-weight / low configuration build system
  • Easy cross compiling, especially for Raspbian
  • Type free string formatting with positional args
  • Documentation stored with the code

From Go:

  • Strict by default
  • No explicit memory managemnt
  • One True Way of formatting and tools to automatically reformat
  • Cheap threads and channels so it’s easy to spawn a statemachine and push/pull events to/from it.

From Python:

  • Optionals (i.e. value or None)
  • Functional style programming via lists and comprehensions

From other places:

  • Dependency injection

My favourite control surfaces are:

  • Prometheus for monitoring
  • logfmt for structured logging that can be grepped
  • YAML or INI for a config language

Prefer using features that come with C++17 over external libraries. Prefer systems that can be self-hosted.

Implementation

The candidates to test are:

  • conan.io
  • gtest
  • Folly
  • Boost, especially Boost::Hana
  • range-v3
  • fmt
  • rxcpp
  • yaml-cpp
  • Doxygen
  • Sphinx

  • rapidjson: has a DOM model and schema validator

  • json11: simple, consise

  • gtest

  • doctest / Catch

Deliverables

How do we know when we’re done?

Milestones

Chunky steps along the way

Milestone Week Result
M1 W1 All foos have bars barred
M2 W3 All bazs are frobbed

Risks and mitigations

What are the risks, likelyhood, impact, and ways of handling them?

Alternatives considered

Do nothing…

Appendix

Building c11.cc:

  • 7.9s with gcc-6.3
  • 7.4s with clang-4.0 (with a link failure, so not exactly the same)