We all love simple things, but many of presented techniques evolved over decades of real non-helloworld development, and not using these leads to programming errors and bloating again. All these people are not stupid — that's not 'look mom, without hands', that's professional experience.
if((r = write(1, toWrite, len)) != (int) len) { /* 1 is stdout! */
If you're going to go to the effort to add the comment, why not just use stdout instead of 1? int written = write(STDOUT_FILENO, toWrite, len);
if (written != len)
{ ...
be simpler ?How would you go about writing something like rsyslog without doing the things they have done?
How would you create rsyslog's flexible (I'm not saying it's "good") module system where people can write their own pluggable custom input/output modules?
Your comment somehow suggests that it's possible to achieve everything they have achieved in terms of functionality while doing it in a much much better way that they just don't know about.
If people writing rsyslog aren't good enough to do it then 99% of other people aren't either.
So let's not blame people, it's the weakness of the language.
If you attempted to create such a module system you will very soon see that doing a lot of the things that they have done is unavoidable (weird naming and so on aside).
I see this attitude where people suggest that writing beautiful secure wonderful C code is possible however just somehow all people are just too dumb to be able to do it.
Every example you show them they say "nah, that person? also too dumb".
You can find similar crap like that example that I pasted in all popular C projects including the Linux kernel and Redis.
At some point does something become not fit for purpose?
I'd say we'd make more progress if we become less tolerant of technologies that disrespect us as humans.
If only an elite subset of people are good enough to program in C. I'd say that's because C is not good enough, not because everyone else is too bad for C.
outputmodule_t omstdout = { .name = "omstdout", .description = "blah", .init = prepare_stdout, .do_action = write_to_stdout }
#if COMPILING_FOR_RUNTIME_LOADING
outputmodule_t *rsyslog_outputmodule = &omstdout;
#endif
Then either stick `omstdout` in a list of modules known at compile-time or compile separately and use dlopen/dlsym to get the one necessary symbol.
No GNUisms, no language extensions, no linker tricks, no macro magic.C has problems but it's not that hard to create readable code in it.
You could get your point across without using that tone.
Rainer Gerhards is a researcher who has published in peer-reviewed journals [1].
Can we please end this "people who write code in a style I don't prefer are idiots" meme?
Most of the research code I've seen if definitely not clean code. And needn't be. (Version Control ? what's that ?)
- Liberal use of macros
- Horribly unreadable coding style
- Needless use of compiler extensions
- Very poorly organized code
This is awful code because the authors are morons, not because the language is bad. They could stand to read this blog post.