And yet you have a strong opinion about how terrible it is.
It is very minimal and it is very readable. It is actually a joy to read. You have no idea what a C-nightmare really is.
Wait, you are telling me, that people write even less readable code in C? Perhaps you are right. Perhaps people can really be that much without care.
It still does not make this code "very readable". If it was very readable, I would have a vague idea about what each of the "functions" does from reading its name or its docstring. Oh wait, there is no docstring at the beginning of each of the "functions" and the name consists of one word, sometimes abbreviated word. And the variable names don't give me hints either. I think our definitions of readable code simply differ quite a lot. When I write code myself, I am unwilling to accept code on that readability level, but we probably have different standards.
Perhaps for entertainment purposes only, you could show me a real C nightmare. I do honestly believe you, that there is worse ;)
I don't understand mathematics, therefore math is undreadable.
I don't understand music, therefore sheet is unreadable.
That is your problem in a nutshell.
Meanwhile, people here take a glance at the code and immediately get it, because it is written in a language they understand. These people tend to find it quite readable -- not necessarily an example of most pretty code, but nevertheless readable.
I may be a C noob, as I already and in an honest way stated in the very first post, but my points still stand. Those are not some subjective things. It is very clear, that those things add to readability, yet the code does not have them.
I'm a person who has written a lot of c, readable and unreadable. It's not that folks don't care; I find that notion slightly offensive. It's that a lot of c programmers care about different things. And, especially those of an older school have a different mindset.
When you read c source, especially that labelled "exercise in minimalism", you should approach it as hallowed. Enter the file with a sense of reverence; lose the ego; ask not why the file wasn't written in service to you. As you have here, tsk tsk. Expect a challenge, a puzzle. Ignore the variable names; they may be misleading -- learn for yourself what role each variable takes on each line -- some of us will reuse a variable for multiple purposes throughout its lifetime. Humble yourself with the understanding that the code was not written for you. It was written for a machine infinitely more patient and methodical than you. Use that machine to execute and debug, watch and analyze, to discover the true meaning.
But, at least to me, it's nothing like poetry. Anyone, without any specific formation, can read poetry and understand something of it. In poetry, artistic license is the exception, not the general rule. The deep meanings, intertwines between form and content, the attention to metre, the use of allegories, and so on, will not be consciously grabbed by every reader. But still anyone that has the base language knowledge required can read it and find some sense to it.
Perhaps people would be less reluctant to show their code in public if it were not so often criticised for falling short of some criteria that the author was never intending to meet?
Ah, let me quote: "Programs must be written for people to read, and only incidentally for machines to execute." – Hal Abelson
And I believe he is right. If you don't write your programs for other people to read, then they not worth being written in that way. Always consider that next person, who needs to read and understand your code. If you don't, then you are not much of a great team player at all. It's great you can do some brain acrobatics, but not much use, if the only one on team being able to understand your code is yourself. I don't know how many 1 person software developer jobs there are still out there, but I guess the number is vanishingly small, compared to team jobs. I would not want someone in my team, who does not pay attention to keeping things very readable.
> Perhaps people would be less reluctant to show their code in public if it were not so often criticised for falling short of some criteria that the author was never intending to meet?
True, you got a point here. But do we want this display of code? However, personally, I'd probably not miss reading such code and maybe it would even be good for the entire profession of software development, if such code was not displayed as something to be achieved but rather something to be shunned.
I write both terse notes to myself, and longer more well-thought out sets of notes to distribute to undergraduates in classes I teach. I wouldn’t give the undergraduates my personal notes - they are simply too unpolished and terse - but my colleagues find them very helpful on occasion. Is it wrong to have two different ways of writing?
I would say this C implementation leans somewhere between “note to self” and “arty exploration”. Is it worth being written? I don’t think you or I could be the judge of that, but the author obviously thought so. Live and let live.
If you think this is unreadable, then you are not qualified to read it --- yet. I implore you to try; maybe it will actually be enlightening.
Perhaps it is not as much that "I can't" because of incapability or stupidity, but simply, that I wont, because of the lack of care given to creating something meeting minimal standards for modern software development and best practices.
Yes, that's all too familiar to me. The dogmatic cargo-culting buzzword-bingo "religion" whose only claim to fame is in effectively producing gargantuan Enterprise Quality™ software --- I mean solutions --- which everyone inevitably hates because they are ridiculously bloated and overengineered to the point that the simplest things take an absurd amount of time and energy, and also have abysmal UX too...
"best practices are best not practiced."
The code quality is terrible. Few explaining comments (actually mos of those are only 1 or 2 words, so not explaining anything at all) and almost all variable names consist of 1 or 2 characters, which do not say what the thing actually is. Then to achieve this arbitrary goal of doing it "in 4 functions" (actually procedures) loads of stuff was apparently stuffed into 4 those 4 functions, so much so, that they are longer than a whole page of code. Most of it looks like gigantic switch statements. It's horribly written code. It looks like what I think of as a C nightmare.
I will admit, I could not write such a thing myself. I lack the knowledge for writing such a low level stuff, do not use C, and if I had that knowledge to do it, my inner drive to do a cleaner job than anything remotely looking like that code, would prevent me from ever sharing such a thing with anyone in public. At least group cases into procedures as it makes sense. Even people writing this low level type of code should be aware of how unreadable that code is, right?