The three exhibits of beginner-vs-expert C code are quite perplexing.
- In the first one, there is advocacy for replacing (pointer == NULL) with (!pointer). I have no issue with either, but to me this sounds like canonical bikeshedding. I would certainly not argue that experts use only (!pointer) and beginners only (pointer == NULL).
- Then it advises replacement of a malloc()ated struct with an on-stack variable containing the same struct (fine so far, why not), then says "the assembly" is even superior if we make that variable "static". This completely glosses over the fact that those three options (malloc, on-stack, static) have completely different legitimate use-cases.
- In the second exhibit, there is a comparison of "glib-style" linked-list (in which the payload is separate, with pointers to it in the linked list), with "kernel-style" linked-list (linked-list pointers as a member structure in the payload structure). The author argues that the latter is what "ace" C coders do. Again, they have completely different use cases. Say you have a large payload structures in an array, and you want to represent a subset of them. "glib-style" can be the right approach then.
- The third exhibit, says "ace" C coders replace "fopen()/fread()" with "mmap()". They do mention in passing the small problem of portability (saying this is solved by just adding #ifdefs and having a separate codepath for Win32). Besides the obvious issues with that, what happens if the input is a pipe?
I find it particularly funny when the article so prominently mentions Dunning-Kruger.