
Arthur Whitney's 'B' Language - chrispsn
http://kparc.com/b/
======
nemo1618
Whitney is so fascinating to me. His code is simultaneously awe-inspiring and
horrifying. It's like he struck a Faustian bargain to gain programming powers
beyond the ken of mere mortals, and is now cursed to write transcendently
beautiful code that manifests as unintelligible gibberish to everyone else.

~~~
userbinator
Everything surrounding APL gives me that feeling, but then I remind myself
that, just like Chinese (which appears just as baffling to those who haven't
learned the language but have experience with Latin family ones only), there's
a not-insignificant number of people who use the language every day and are
highly productive at it.

I like terse code and my style is closer to the early UNIX/K&R, yet I've
noticed a lot of people already find that too terse; the "normal" style these
days seems to be gradually getting more and more verbose (look at typical C#
or Java, for example.)

IMHO the readability argument in favour of verboseness is a bit of a misnomer
--- you can easily "understand" a file full of extremely verbosely named
functions all consisting of a single line, but that doesn't help at all with
seeing the big picture. Judging by the amount of file-flipping and stack-
jumping when I have to debug a project in that style, it probably hinders it.

On the other hand, this is "code with a learning curve". You can't glance at
it and understand immediately, but once you do take the time to read it
carefully, you can understand more of the whole than if it was written in a
more verbose style.

~~~
bunderbunder
My sense is that, once you get to a certain size of project, it becomes both
impossible and undesirable for everyone in the project to be able to keep the
whole thing in their head. And that this boundary is something of an event
horizon in terms of what's desirable in a coding style - up becomes down and
down becomes up.

There's also a lot of code that's so tightly coupled to some business domain
that it's natural to write it in the language of the business. That way you
don't have to maintain separate mental models and translate between them.

------
yiyus
I studied this code for a long time. I have lots of notes, going through
everything almost line by line. I would be embarrassed of making them public
because I never finished (at some point, I was just rewriting the x64
reference), but if somebody is interested I do not mind sharing.

I would recommend everyone doing C to have a very careful look at this. The
code is full of nice tricks and you start appreciating the terse style after a
while. I understand why this style is not more commonly used, but I really
like it.

~~~
mamcx
I wish* exist a simplified implementation of this (or APL) in "normal" looking
code.

Array languages are the most "obscure" of all paradigms I have looked into.
Even concatenative ones have some few resources about how work.

Also, the community live in a parallel world! So when asked about stuff,
redirect me to
[https://code.jsoftware.com/wiki/Essays/Incunabulum](https://code.jsoftware.com/wiki/Essays/Incunabulum)
or [https://github.com/kevinlawler/kona](https://github.com/kevinlawler/kona)
as if it somehow make everything so obvious ...

P.D*: Because I'm building a language that try to draw some ideas from kdb

~~~
5166cc9c39fa61
> Array languages are the most "obscure" of all paradigms I have looked into.
> Even concatenative ones have some few resources about how work.

Have you tried looking at APL books? There are dozens of books on APL you can
find. There are journals and conference proceedings from ACM, IBM, Dyalog, and
Vector UK. I started to get into APL more seriously last year and lack of
resources is definitely not a problem in my experience, lack of time to read
them all is. Also, it's more about thinking of algorithms in terms of matrix
and array operations. A lot of the techniques and algorithms can be easily
adapted from Matlab.

~~~
4thaccount
Well there are books like "Mastering Dyalog APL", but they don't help you
think in the language. There is the "Finnish APL Idioms" book which helps a
bit. APL and J certainly have libraries, but a lot of functions and libraries
that are builtin to most languages are omitted from APL as you can replicate
with 3 characters. That's where knowing idioms helps. I am just a novice, but
really enjoy writing APL & J. Aaron Hsu has been on a couple of APL related
posts on HN that I have linked to multiple times. He is a scheme guru that
switched to APL a few years back and wrote the Co-Dfns parallel GPU compiler
for Dyalog APL. He has some enlightening talks on YouTube as well. I mention
him here as his APL code is extremely terse and similar to Whitney's C, and he
did an excellent job defending it in the HN post which changed the way I look
at code. Second, as a University TA, he's taught multiple courses on APL as a
first programming language and has talked about writing a book that tries to
teach how to THINK in APL and not just this is how you transpose the matrix
using this symbol...etc. My problem is that I know what the symbols do, but
don't know how to switch from imperative/OO thinking to how to think in terms
of array primitives (inverse, transpose, sort, outer product...etc).

~~~
avmich
"J for C programmers" is, in my opinion, an excellent resource for how to
think in array-oriented style.
[http://www.jsoftware.com/help/jforc/contents.htm](http://www.jsoftware.com/help/jforc/contents.htm)

~~~
4thaccount
I've flipped through it before, but didn't remember it being very enlightening
(note that I didn't read the full thing and do all the excercises). I'll have
to give it another shot. Thanks for the tip!

------
ptrott2017
For those interested but needing a little help deciphering Thomas Lackner has
a handy repo:

[https://github.com/tlack/b-decoded](https://github.com/tlack/b-decoded)

------
QuentinM
Q is one most important language here at BitMEX. Complicated or not, it's on
KDB that all our trades happen, up to $8B in 24H volume last summer - it's
highly efficient at its task, and never made us or any of our customers, loose
a single Satoshi.

~~~
abeaulne
With all due respect, requests to BitMEX during times of high load have >50%
probability of hitting a 503 Service Unavailable error. Meanwhile, competitors
with similar volume/activity don't have this problem.

~~~
UncleEntity
They've done studies, you know. They say 60% of the time, it works every time.

------
jshaqaw
Whitney’s code is what I expect code to look like post-singularity when hyper
intelligent AI program themselves!

~~~
mark_l_watson
+1 thanks

You got me thinking how AlphaGo reinvented the style of Go for human players.
A real AI taught one of our programming languages would code in a way that
would be alien to us.

Whitney’s code is fascinating. I thought that someone might use a good C IDE
to rename symbols to longer human readable names, but, that would harm the
terseness of the code.

------
stesch
Doesn't look like B. I'm a bit irritated.

[https://en.wikipedia.org/wiki/B_(programming_language)](https://en.wikipedia.org/wiki/B_\(programming_language\))

------
5166cc9c39fa61
I think a good introduction to this style of coding is the first "proof of
concept" prototype interpreter for a small subset of J, also written by
Whitney:

[https://code.jsoftware.com/wiki/Essays/Incunabulum](https://code.jsoftware.com/wiki/Essays/Incunabulum)

Once I realized it was K&R C, I thought it was pretty straightforward.

~~~
leni536
I ran it through gcc -E and clang-format.

[https://pastebin.com/21qiRDi5](https://pastebin.com/21qiRDi5)

~~~
5166cc9c39fa61
And not surprisingly that makes it less readable. It is a lot harder to have
one-character names when you need to scroll across many pages to look up what
they mean. So the more code you have, the longer code you need. As Eric Evans
points out, naming things in computer code is difficult and important; wrong
names can be misleading. This style avoids the problem by avoiding names.

------
rmbryan
This was helpful to me:
[https://en.wikipedia.org/wiki/K_(programming_language)](https://en.wikipedia.org/wiki/K_\(programming_language\))

------
gricardo99
This is from 2015. I really wish something more from Whitney/kparc would
materialize.

Whitney/kparc previously covered on HN:

[https://news.ycombinator.com/from?site=kparc.com](https://news.ycombinator.com/from?site=kparc.com)

~~~
tlack
He just released a new product a few weeks ago:
[http://shakti.com](http://shakti.com)

Downloadable now:
[https://www.reddit.com/r/apljk/comments/b1l5hi/shakti_trial_...](https://www.reddit.com/r/apljk/comments/b1l5hi/shakti_trial_via_anaconda/)

Didn't get much attention on HN:
[https://news.ycombinator.com/item?id=19326007](https://news.ycombinator.com/item?id=19326007)

~~~
dang
It got attention here:
[https://news.ycombinator.com/item?id=19418570](https://news.ycombinator.com/item?id=19418570).

------
azhenley
Well, at least there are comments, right?

~~~
yiyus

        // :+-*% ^&|<=>  x64 JJ Jj o2 cc tst RET cll psh pop acdbsbsd89..  o[m[s|d]] c3 eb+1 e8+4 e9+4 [f2/66/4*][0f] 5* 7*+1 b*+4 0f8*+4  03 23 2b 3b (6b 83) 89 8b ..

------
3xblah
[https://gitlab.com/k7db/k](https://gitlab.com/k7db/k)

Wasn't this public?

[https://duckduckgo.com/lite/?q=https://gitlab.com/k7db](https://duckduckgo.com/lite/?q=https://gitlab.com/k7db)

Reference:
[https://cs.nyu.edu/cs/faculty/shasha/papers/tutorial](https://cs.nyu.edu/cs/faculty/shasha/papers/tutorial)

~~~
SifJar
Binaries can now be obtained from Anaconda:
[https://anaconda.org/shaktidb/shakti](https://anaconda.org/shaktidb/shakti)

Not sure what was on gitlab, I assume not source?

~~~
3xblah
The install for Anaconda is over 500MB.

If it is anything like k, the "shakti" binary is probably small, maybe under
260KB.

Is there a way to download just the shakti binary?

What are the restrictions on the trial version of shakti?

Is it time-limited (e.g., 30 days)?

Does it need an internet connection to be able to phone home? (I think FD/Kx
started doing this with their 64bit trial.)

The backstory for all this is that Whitney sold his remaining interest in Kx
around July of last year for around 53 million.

Quick US trademark search does not show any filings for a "shakti" mark that
covers computer software.

~~~
lelf
Just download it ‘manually’
[https://anaconda.org/shaktidb/shakti/files](https://anaconda.org/shaktidb/shakti/files)
and tar -xf

bin/k is 185K

~~~
3xblah
Thank you! Exactly what I was looking for. Even give us a static binary.

Alas, I am getting "Illegal instruction (core dumped)". Will have to try
another kernel.

~~~
yiyus
You need avx

~~~
3xblah
I guess I need to try a different CPU. Cheers.

------
egwynn
Why does the makefile need to run $(CC) under sudo?

~~~
akkartik
It's writing directly to _/ bin_.

~~~
egwynn
Got it. I guess that answers my question but leaves my eyebrow raised.

~~~
theamk
Is that the only thing that makes you raise your eyebrow?

:)

~~~
egwynn
If I’m honest, I think it’s the most intelligible file in the folder (besides
the readme) so its issues were more accessible to me.

------
caymanjim
This code is a horrid abomination. I don't care if this guy is a genius and
could single-handedly write the best OS in the history of computing; his code
is write-only, unmaintainable garbage. There's nothing elegant or praiseworthy
about this at all.

~~~
ulucs
If you don't know the language, of course most things will seem understandable

    
    
        b[Ii]{h:#x;l:0;while(h>l)$[y>x[i:/l+h];l:i+1;h:i];l}
        b -> function name
         [Ii] -> type declaration
              h:#x;l:0; -> initial definitions
    

And the rest of it are bog-standard binary search operations with implicit
return of l. Honestly, it's more understandable than Java with annotations or
other magic constructs

~~~
caymanjim
itsnotthatitcantbereadbysomeonewhoknowsthelanguageitsthatitsincrediblydenseandhardtoreadandlacksanymeaningfulcontextclues

~~~
3xblah
I actually had no problem reading that!

At first glance, it looks unsightly but when one actually starts _reading_ it
(all of it, not just looking for "clues"), how it looks makes little
difference.

These threads that mention k are always entertaining. There is usually some
amount of comments like yours.

There is this concept called "Tall Poppy Syndrome". I am not sure what we
might call this stuff here (it should have name), but we see some of it every
time k comes up in a thread on HN.

Fortunately we also see people commenting who like APL or at least are
curious. Not everyone is trying to cut Arthur Whitney down for being good at
what he does.

------
biosed
Did he ever release K OS?

I seen a few bits and pieces from Geocar but never seen a release or download.

------
recursive
It says same ops, but it seems some are missing? I see no modulus. Am I
reading this right?

------
3xblah
Where is k.c?

~~~
icen
Why would you expect a k.c? This is b. There's a b.c.

~~~
tluyben2
It's referenced in the Makefile.

~~~
theoh
On a possibly unhelpful tangent, I'm expecting it to look something like this:
[https://code.jsoftware.com/wiki/Essays/Incunabulum](https://code.jsoftware.com/wiki/Essays/Incunabulum)

~~~
ColanR
It sure does: [http://kparc.com/b/b.c](http://kparc.com/b/b.c)

~~~
theoh
I'm so tempted to just respond with "wanker", though I know HN norms don't
allow that. Either the code is for human consumption (in which case, fulfil
that goal) or you're writing demoscene assembler which displays virtuosity
without any positive impact on society.

~~~
ColanR
I think the problem is, we intuitively estimate the readability of code based
on the space it takes up, when we should take into account the information
density.

That code is extremely readable - if you assume it will take just as long to
understand as the entirety of the GCC compiler: [https://github.com/gcc-
mirror/gcc](https://github.com/gcc-mirror/gcc)

~~~
avmich
Read "A programming language", where APL came from -
[https://www.amazon.com/Programming-Language-Kenneth-
Iverson/...](https://www.amazon.com/Programming-Language-Kenneth-
Iverson/dp/0471430145) \- you might get more understanding why it is the way
it is.

It is the mathematical notation, put into, as Dijkstra expressed,
"technologies of the past", completed (to be Turing-complete) and made
executable.

At least, I think, this is the basic idea.

------
otikik
Programming is not telling the machine what to do. That's the easy part.

What programming is about, and what's hard, is telling _the next programmer_
what the machine does.

This makes the easy part a bit easier, and the hard part much harder, than
using C. And I already disliked C to begin with, for similar reasons.

~~~
quadcore
Now I think you're right, but there is two strategies which boils down to the
following: "you can either make a program that's so complex there is no
obvious defect, or you can make a program so simple it's obvious there is no
defect."

What it says is that the hard part to make the next programmer understand what
the machine does is not reading code, it's code complexity. Training yourself
to read terse code is O(1), understanding code is at least O(N) where N is the
number of lines of code.

Before you start arguing, _try it_. Try writing code as simple and succinct as
possible. You won't go back to anything else because it works. It does make
programming simpler and more productive.

~~~
theamk
I did, once, when I was at school. It was great - everything was so fast to
type, the program (a somewhat complex game) would fit in on two screens. I
almost finished it in a week.

And the I had exams, and did not touch the computer for two weeks. When I came
back, I forgot it all. Cx? Dzy? Those names were meaningless.

This was a very importantly lesson - programs must be maintaineable. Unless
you want to spend your entire life working on a single piece of software, you
want to be able to context switch, and do it quickly.

~~~
RodgerTheGreat
Many people use descriptive variable names to carry semantic information.

APLers use extremely consistent, stereotypical naming conventions which also
carry semantic information. Think "Hungarian Notation" except it's just the
prefix part. With consistently applied terse names, the same idea will result
in the same code. Easier to visually pattern-match.

It's also worth considering that longer names are not necessarily more
meaningful. It's pretty common for everyday programmers to use single letters
for something like a loop induction variable. Sometimes longer is just...
longer. Consider these three semantically identical K definitions:

    
    
        a:{x*x}
        b:{[n]n*n}
        c:{[number]number*number}
    

Is that third version _really_ clearer than the first?

~~~
bakul
Most people have difficulty with the fact that an array expression can very
compactly represent some powerful functions. For example,

    
    
      (+/*)\:
    

is matrix multiplication. The following computes the transitive closure of a
binary relation (represented as a boolean square matrix):

    
    
      {x|x(|/&)\:x}
    

Its core has a similar "shape" as matrix multiplication:

    
    
      (|/&)\:
    

So in a sense variable names don't matter all that much! To grok this code you
have to stop thinking in terms of item at a time operations and start thinking
of operations over collection of items. If you know how to write unix shell
pipelines you are already somewhat familiar with this paradigm except that a
shell doesn't provide most of the more useful features of array languages!

------
jonathanhd
Whitney follows the enlightened solution to the NL=\n|\r\n debate, just don't
end your lines ever.

~~~
seanmcdirmid
It is notable that newlines are a relatively new invention anyways in the
history of writing. But then again, so is white space.

