Re:Software error doomed Japanese Hitomi spacecraft
by woodman on Sunday May 01, 2016 @01:59AM
(#11605062)
I've tackled some problems that would have ideally, from a performance perspective, been implemented with very deeply nested if()'s. I've found a truth table like layout of bool evaluations to be a nice compromise between maintainability and performance:
void doit(const tststructptr* in) {
assert(in); /* Because we test our code, for safety */
const tststructptr t = *in;
if ( t.t1 && t.t2 && t.t3) { f1(); }
else if ( t.t1 && !t.t2 && t.t3) { f2(); }
else if ( t.t1 && t.t2 && !t.t3) { f3(); }
else /* TODO: Fix, this should never happen */
releasenerveagent(SLEEPINGQUARTERS);
}
A long sequence of ternary operators allow for a prettier layout, but is more error prone.
The priority seems to be reliable real-time computation, and the solution is to calculate everything as a continuous function. Anything that would be a branch is instead a binary mix of the conditions, triggered with a threshold function.
I can think of many ways of structuring programs which are spaghettiish in C, but would yield the desired results in an automotive ECM.