13
ddephor
7y

My first task in my current company, a few years ago.

I had to add features to a 10 year old microcontroller-based device written in C.

There was a struct named "global", which held hundreds of other structs that held variables or even more structs.
If one would have printed the structure of this mess it would haven needed several pages.

This "global"-struct was used in every single sourcefile to store and pass data around. Obviously there was no documentation and often useless comments.

Additionally there were a few protocol stacks involved, mainly similar, only differing in one or two protocol layers.
The implementation of the protocol stack was by setting flags in the "global"-struct in every protocol layer and having the application data in a buffer.
The complete telegram with all layer specific data (header, checksums, etc.) was then build at one single point right before sending it, based on the flags and the data buffer.

As there was no chance to reuse protocol layers with this implemenation. Three protocol implementations with special telegram builder existed in parallel, although they were nearly identical.

I needed a fourth variant of the protocol stack, so I had no chance but to make another copy with some minor changes.

But there was a benefit from this task.
As I had to do the software for the successor of this device from scratch I learned for many things how not to do them :-)

Comments
Add Comment