50 comments

[ 3.8 ms ] story [ 56.6 ms ] thread
During code reviews I would always ask for clear code because it's much harder to tell whether it's correct if it's unclear.

I got too much other stuff to do than decode the voynich manuscript...

Holy molly this must be the equivalent of reading the necronomicon and getting cosmic madness disease as a result.

What a flex of patience!

The way to understand Arthur Whitney's C code is to first learn APL (or, more appropriately, one of his languages in the family). If you skip that part, it'll just look like a weirdo C convention, when really he's trying to write C as if it were APL. The most obvious of the typographic stylings--the lack of spaces, single-character names, and functions on a single line--are how he writes APL too. This is perhaps like being a Pascal programmer coming to C and indignantly starting with "#define begin {" and so forth, except that atw is not a mere mortal like us.
This code style is psychotic. I had to reverse-engineer and verify a C codebase that was machine-obfuscated and it was still clearer to follow than this. Increasing clarity through naming is great, but balancing information density is, dare I say, also a desirable goal. Compacting code rapidly diminishes returns once you're relying on a language having insignificant whitespace.
I can’t explain why but “He’s assigning 128 to a string called Q” made me absolutely lose it.
> His languages take significantly after APL, which was a very popular language for similar applications before the invention of (qwerty) keyboards.

Ok, so this article is tongue in cheek. Good to know that up front.

Kudos on not just taking a combative stance on the code!

This was a very fun read that I'm fairly convinced I will have to come back to.

There are best or accepted practices in every field.

And in every field they work well for the average case, but are rarely the best fit for that specific scenario. And in some rare scenarios, doing the opposite is the solution that fits best the individual/team/project.

The interesting takeaway here is that crowd wisdom should be given weight and probably defaulted if we want to turn off our brains. But if you turn on your brain you will unavoidably see the many cracks that those solutions bring for your specific problem.

Ah yes... very tempting to ask an AI to refactor some large Java program (pick your language) "in the style of Arthur Whitney".
Much as a Real Programmer can write FORTRAN programs in any language, Whitney can write APL programs in any language.
The C preprocessor allows you to define a limited DSL on top of C. This is... sometimes a good thing, and often convenient, even if it makes it hard to understand.
This is a good use of macros. I understand people are frightened by how it looks but it’s just C in a terse, declarative style. It’s mostly straightforward, just dense and yes - will challenge you because of various obscure macro styles used.

I believe “oo” is probably an infinity error condition or some such not 100% sure. I didn’t see the author discuss it since they said it’s not used. Was probably used during development as a debug printout.

```

#define _(e...) ({e;})

#define x(a,e...) _(s x=a;e)

#define $(a,b) if(a)b;else

#define i(n,e) {int $n=n;int i=0;for(;i<$n;++i){e;}}

```

>These are all pretty straight forward, with one subtle caveat I only realized from the annotated code. They're all macros to make common operations more compact: wrapping an expression in a block, defining a variable x and using it, conditional statements, and running an expression n times.

This is war crime territory

(comment deleted)
Reminds me of a Python codebase I used to work with

The company was originally a bunch of Access/VB6 programmers.

Then they wrote their VB code in PHP.

And then they wrote their PHP code in Python. It was disgusting.

You will not become smart, only crazy and unemployable. :)
The person who wrote this code might be a genius, but learning to read it isn’t going to make anyone smart. It’s basically obfuscated assembly code.
> "Opinions on his coding style are divided, though general consensus seems to be that it's incomprehensible."

I wholeheartedly concur with popular opinion. It's like writing a program in obfuscated code.

Hmmm... his way of basically making C work like APL made me wonder: Is there a programming language out there that defines its own syntax in some sort of header and then uses that syntax for the actual code?

Is this supposed to be a specific coding style or paradigm?

I’ve never seen code written like this in real-world projects — maybe except for things like the "business card ray tracer". When I checked out Arthur Whitney’s Wikipedia page I noticed he also made the J programming language (which is open source) and the code there has that same super-dense style https://github.com/jsoftware/jsource/blob/master/jsrc/j.c

[flagged]