5 ms·
Of all the things I've seen in my time writing software I can qualify that some of the most fucked up things involved state machines. The worst of which was a 2
by iasay 4y ago
Of all the things I've seen in my time writing software I can qualify that some of the most fucked up things involved state machines. The worst of which was a 200 state hand written one in C for an embedded measurement system. There was no documentation, no comments and the states were numbered rather than named. The guy who wrote it originally was "anti RTOS" and had died after riding his motorbike recklessly leaving this shit for everyone to deal with.
It took me two weeks to do a trivial change because I had to reverse engineer a ton of it. And the only debugger I had was a couple of LEDs on the board I could wiggle on and off.
- languageserver 4y agoSend this by mail to thedailywtf, would love to read the expanded version
- contingencies 4y agoSounds like a confused author or potentially an implementation-driven architectural decision (eg. regulatory or policy requirement, direct map from exposed states of a prior implementation that had been black box reverse engineered, etc.). AFAIK the normal way to implement state machines in embedded since ages yore is to use interlocking networks of state machines per isolate subsystem. At least, that's what I do and that's what seems natural in C and assembly where concerns such as manual memory management, code re-use and programmer cognitive load would all tend toward such an architecture. What was the hardware?
- iasay 4y agoWas Coldfire + IAR. The design was driven entirely by idiocy and showboating. I was hired just to limp it along a bit further while they spun a new board and software as the MCU was obsolete anyway.
- kevin_thibedeau 4y agoI call this crap enterprise grade spaghetti code. It's "structured programming" with dynamic dispatch of gotos.
- knodi123 4y ago> The guy who wrote it originally was "anti RTOS" and had died after riding his motorbike recklessly That's literally the example in the literal textbook of why you shouldn't write code like this!