https://codeberg.org/ngn/k/src/branch/master/v.c
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!?
https://codeberg.org/ngn/k/src/branch/master/v.c
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've been fascinated by this style ever since I saw the "J Incunabulum." Unfortunately, it seems to come from idol worship.
Is that true?
Isn't this style just a natural place to arrive after agreeing with and understanding "Notation as a tool of thought"?
Also while learning J/K I didn't notice much of this worship.
I'm afraid of writing off a purposely chosen style as one that has no merits and is explained by idol worship.
Arriving to your comment late; I apologize.
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 just writing C in the style of the target language. If you can read K, reading that C isn't especially hard.
Some writings on this style:
https://code.jsoftware.com/wiki/Essays/Incunabulum
https://github.com/kevinlawler/kona/wiki/Coding-Guidelines
That does not make me want to learn k.
Learning how to write K is way less painful than learning how to write C in the style of K.
You may want to learn J if you read "J for C programmers" - https://www.jsoftware.com/docs/help807/jforc/contents.htm . A great book.
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:
Just use words like a normal human:
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).
> ngn/k is certainly a lot of fun to use. I just wish it also worked on OS X (& plan9).
To start on MacOS, can apply this patch then run `make k-libc` on OSX 12.0.1 (M1 processor):
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.
[1]: https://codeberg.org/ngn/k/issues/30
I have tried something similar to this but its self tests still don't pass. Will give this a try. Thanks!
It's an imitation of Arthur Whitney's "iconic" style.
Identical formatting to the commercial offering.
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:
'k' gets redefined and LOLs all around.
Well, for what it's worth, the strings with curly braces are K code.