3 ms·
It sounds like interesting advise. Why the liberal use of structs?
by chris_wot 3y ago
It sounds like interesting advise. Why the liberal use of structs?
- actionfromafar 3y agoAfter looking at too many char arrays with fields indexed by various #define SOMEINDEX 6, and such, I have come to this conclusion. Code like that, where the knowledge of the data structure is "sprinkled out" in lots of code with if-s and other conditionals, which all have to be updated all over the code base, should one want to change what the data structure looks like. I don't want to point fingers so I won't name names, but I took an interest in a certain file system for embedded flash because it was very good, struck a nice balance between features, size and speed, had lots of regression tests etc. In many ways a high quality product. But wow was it coded very much like that, where to read the code you had to have a full mental model of the layout on "disk" and the layout of the data structures in RAM. If it had set/get/manipulate_or_update functions operating on structs, then serializing code for the structs to disk, it would have been much easier to read. (And I don't mean heavy serializing, structs with appropriate packing instructions to the compiler would have probably sufficed.) Edit: Yet another reason to use structs, don't use naked arrays, put a size_t and the array in a struct. https://news.ycombinator.com/reply?id=39440071&goto=threads%3Fid%3Dactionfromafar%2339440071 https://news.ycombinator.com/reply?id=39440071&goto=threads%...