Where does this madness come from, and why does it infect proponents of array-based languages to the point where they start writing C code in this style!?
I've been fascinated by this style ever since I saw the "J Incunabulum." Unfortunately, it seems to come from idol worship. Arthur Whitney, the author of the K programming language(s) writes in this style, and so those who seek to emulate his achievements sometimes do as well.
Some of my complaints:
* true adherence to the source material requires one to dispense entirely with all but the tersest comments
* it over-aggressively tunes away whitespace (if you code like this, it's quite beautiful when you align comparable values on the same column between adjacent rows)
* many of the idioms rely on undefined behavior, which makes it very frustrating to maintain, port, and extend--to a lesser degree, it makes the code hard to follow, but usually (the most frustrating part of all!) is that the intent is _clear_, it's just that it doesn't work well with the C standard
* it emphasizes the placement of as many statements as possible on a single line, which is jarring when those statements don't flow together; on the other hand, the style is quite nice when you allow yourself to place complete and related concepts together, since it's clear that you're "doing something else" on subsequent lines
I said this is "unfortunate" not because I have any problem with Arthur, but because I actually wish this was part of a richer tradition of C (which I've never been able to confirm and thus came to my conclusion about idol worship). Although I happily abide by them in my professional life, I am thoroughly frustrated with coding standards that dictate variable names be complete sentence and code limited to 80 lines. I would love to adopt a rigorous style _based on_ Arthur's, although I will concede that this will probably never happen because the aesthetic of this practice conflicts so completely with the contemporary zeitgeist.
Anyway--nobody has to like it, but some people really actually do like it and accomplish work with it.
I want to be clear that I think this style does indeed have merit, regardless of its origins. I like it--I prefer _reading_ and _comprehending_ code rather than superficially skimming code--I believe the style serves that goal wonderfully. I do not think that a thing adopted because of one's respect and adoration for an idol figure invalidates the value of the thing, _but_ I also think I spoke much too harshly and I recognize that people are allowed to like a thing and take it from another person without idolizing the creator.
However, I still believe the style originated with Arthur. Again, I don't think that's bad, and I agree with you that there is indeed some spirit of Iverson's work spread around different computing communities in the way they write C. Then again, _I_ did not have the presence of mind to spontaneously write Arthurian C without reading his code first and thinking really hard about it, so I am perhaps making the mistake that everyone else is similarly limited. I've tried to find independent exemplars of similar styles without success. Again, I write that down as a personal failing.
It’s odd, I seem to remember comments from you on a similar thread about a year ago. https://news.ycombinator.com/item?id=27220613 Are you still shocked or have you just forgotten?
Indeed. But that was in reference to the actual array-programming language. I get that they have their own special syntax, and the terseness helps in a way.
One talk I saw by a proponent explained that the intention is that you often change just the trailing character (or 2 or 3) to "twiddle" a query until it does what you want.
That interactivity makes sense to me. I do similar things with query languages like KQL.
But... in C? It's compiled! You have to "run" it!
Not to mention that it makes no syntactical sense in C to be fiddling around with suffixes. It has nested brackets that need to be properly closed! It's procedural, not declarative, so even if you condense the syntax, you don't "win" that much in the end.
There is literally no way that anyone could ever justify using single character source file names. That's just absurd. Note that the author had to put a little table explaining what each single-character file does/contains.
WHY NOT JUST NAME THEM to match their function!?
So instead of this madness:
0.c syscalls and main()
m.c memory manager
p.c parser
k.h embedding api
a.h common header
g.h header generated by g.k
Are you saying this is a complex system or that any decisions made in the context of complex systems must be used for all software? Also, this was not in response to a post about documentation but rather a post about the file names. In any event, it says nothing about my experience and you are simply extrapolating.
You can always write documentation in comments. Using terse names for the identifiers when feasible can make it a lot easier to see the bigger picture wrt. multiple components interacting. It's a tradeoff.
The code referenced here is pretty extreme NOT providing the guidance, hence my response to the poster defending the extreme and ridiculing the good practice.
Because I can already look at a sock and see it's a sock.
If you're keen on this style, perhaps you should pack all the socks, underwear and other objects in your home into identical boxes and put labels like "~" and "z" on them.
I do. You're saying you see your code as a personal posession, whose structure you know and understand. You're saying it doesn't matter how easy your code is for somebody else to get their head round because, like your sock drawer, you don't imagine other people will go rummaging around in it.
It's not an attitude I approve of in colleagues, for obvious reasons. Fortunately it's a long time since I've had to work with anyone that thinks that way. They don't survive in workplaces like mine.
Which colleagues are you talking about in this context? In any event I’ve worked for over twenty years in companies with thousands of employees and I can’t remember a single time that the name of a source file made any practical difference in my day. I think the naysayers are having their own conversations distinct from actual reality of what’s happening here. “I wouldn’t do this” is a perfectly reasonable reaction but not at all useful in a public discussion.
I know C and many other programming languages reasonably well, though K not at all.
Are there people (other than the author) who look at this source code and read it fluently? There appear to be few clues as to the meaning, in terms of naming choices (of any identifiers), comments, formatting, etc.
Arthur Whitney created a compiler called b that “compiles a language that is isomorphic to c” (his words) and compiles 1000 times faster than gcc etc.
The b language code looked very much like k but was essentially exactly equivalent to a subset of C. I read he abandoned it for other reasons but that would not be a bad way of writing a k implementation! “Same madness”:-) May be ngn or someone else would get inspired to write a translator from b to C.
ngn/k is certainly a lot of fun to use. I just wish it also worked on OS X (& plan9).
However, Apple platforms are not officially supported (or to put it more bluntly, "officially not supported"), and there are bugs such as this one[1]. I suspect it has to do with libc differences on Mac versus Linux. If you have experience with the libc differences between Linux and Mac, I'd welcome your input! I'm not an ngn/k developer, just interested in adding support for MacOS.
This is how they roll in the k world.
Imagine including k.h in an external application that wants to use some k functionality and the existing code uses the single char looping idiomatic code:
Where does this madness come from, and why does it infect proponents of array-based languages to the point where they start writing C code in this style!?