Embedded software design patterns Entry: Separate allocation from initialization Date: Mon Jun 13 18:23:37 CEST 2011 This has two pilars: * Separate construction from functionality (make the code stateless). * Factor construction into initialization and allocation, and allow allocation to be done at compile time. I.e. using CPP macros or C++ templates. Entry: Making up binary tags: always use flat encoding Date: Mon Jun 20 18:41:28 CEST 2011 It's a royal pain to encode hierarchical data structures in a binary protocol (i.e. type tagging binary serialized data). However, it seems simplest to just centralize this information, because any form of hierarchical allocation seems to introduce more arbitrary decisions. ( Note: in most representations objects are already flat-tagged, using a memory pointer! ) The same goes for error codes. Entry: Design for robustness Date: Thu Dec 29 10:23:29 EST 2011 The project I'm currently working on seems to have a huge amount of code dedicated to robustness and error handling / recovery. The main problem being that all those little patches and tweaks are distributed all over the code, instead of being part of the design (make the design robust first, then make it do what you need..) Is there a way around this? How to really design good, robust code? I'm thinking about Erlang's "let it fail" model, but how can you take the gist of this and make it work in a small embedded C application?