What about K?
142 comments
·February 10, 2025airstrike
skruger
That’s nice of you to say so.
bear8642
The about section has links to other things he's written/presented.
jyscao
>for which I only have a perennial curiosity.
Guessing you meant to say "peripheral curiosity" here? Perennial would mean you have a long-lasting and/or continued interest/curiosity.
airstrike
I was wondering if anyone would find that unusual! It's long lasting but never rises to anything more than curiosity, so I wanted to juxtapose the two to convey the mixed feelings I have for it.
pie_flavor
> Readability is a property of the reader, not the language.
Uiua[0]'s stack model is much more annoying to work with, but I really appreciate its embrace of unicode glyphs. Every other derivative of APL throws those out at the first opportunity, but when you have a lot of glyphs, you stop being so tempted to make different arities cause the same glyph to mean wildly different things, when the arity is not actually written down explicitly and depends on whether the next thing to the left is a parameter or another function. Once you can See The Matrix, this is the chief thing that still does make K and friends objectively unreadable in a way they don't have to be.
[0]: https://uiua.org
xg15
I appreciate the idea (and Uiua's examples indeed look beautiful, almost like visual programming) but I'd at least like some obvious way how to pronounce the code.
RodgerTheGreat
All of the symbols in Uiua have short english words as alternate names, and the online editor allows you to type them by alias.
K has "traditional names" for all the primitive operators which appear in reference cards and which are typically used when discussing code aloud with other K programmers. Q and Lil, which are both K descendants, outright replace some symbols with those named keywords. Named keywords can make the primitives superficially easier to remember, at the cost of making idiomatic patterns in the language less visually apparent.
xg15
Ah, that makes a lot more sense. Thanks!
gweinberg
Original quote is just mind-bogglingly stupid. If If I can't read any programming language, that's a defect on my part. If I can read pretty much any language except k and brainfuck, that's a sign k is particularly difficult to read.
BoiledCabbage
> Original quote is just mind-bogglingly stupid.
To be frank, your quote is mind-bogglingly stupid. How easy do you think Java is to read to a native Greek speaker with no English language knowledge? Would the Java standard library be as easy for you to read if it were written in Greek? Would java still be an easy to read language if all the keywords and library were in Greek?
If your only definition of a good programming language is one written in your native language and a PL becomes bad if written in a different language, then your criteria is terrible/useless. And right now that's your criteria.
russellbeattie
> "there is no single definitive k, but instead a sequence of slightly incompatible versions. If you decide to stick with k, you’ll see mentions of k4, k5 etc."
I don't know about the qualities of k itself, but I think the idea of having a common practice for experimental programming languages to be grouped under a single name like "E" with a number is quite attractive.
There are lots of students, hobbyists, researchers, professional devs and companies who are developing their own working programming language. There are a million of them, all with their own names. 99.9% of them are ignored, or criticized unfairly by others expecting fully fleshed out features.
I can imagine a GitHub repo where you can register a new language "En" (with n being a number) rather than it living in obscurity on a random website. Then others can jump in and experiment with the language and give it feedback, fork it, etc.
This isn't just for toy languages, but for big organizations like Google. Instead of naming a not-fully-baked C++ successor as "Carbon" and getting flak for it not being ready for real world code yet, they could simply call it "E321" and the status of the language would be self-explanatory.
Then if one of the E languages gains enough traction, it could "graduate" to its own named language.
I also like the cred that an "official" E language could get when a dev talks about it to others. Everyone would immediately know it was experimental and where to see the code.
pjmlp
What seems to be a pity about most array languages is that in theory, they would be ideal DSL languages for SIMD and MIMD code exploration, but as far as I understand from ArrayCast guests, most are still interpreters at heart focusing on plain CPU execution.
dzaima
The big problem with using array languages for lower-level SIMD stuff is that that generally requires some amount of typedness, but tacking on types on an array language without ending up with having types be the majority of the syntax and code (or taking up a ton of mental capacity if utilizing very heavy type inference) would be rather non-trivial. And the operations you want for lower-level ops are quite different from the higher-level general-purpose ones too. (and, of course, some interpreters do make good use of SIMD and/or multithreading)
That said, some form of array language more suited for stuff like that is a somewhat common question; maybe one day someone will figure it out.
Vanessa McHale is doing some interesting work on a typed compilable array language, Apple[0].
[0]: https://github.com/vmchale/apple/?tab=readme-ov-file#apple-a...
pjmlp
Thanks for the hint.
While we have CUDA being polyglot, it is still pretty much C and C++, or shader languages, hence why I keep thinking why not an array language that is also a kind of shader language DSL.
dzaima
Oh, another interesting thing is http://beyondloom.com/tools/specialk.html - a simple k DSL for shaders. Though it still follows the shader language paradigm of running the function for each pixel separately, rather than the array language paradigm of taking & returning a list of things to process.
oxavier
Not exactly the approach your describing, but Futhark[0] offers an alternative to CPU execution, it compiles to CUDA or OpenCL to run on GPU (or multi-threaded CPU).
pjmlp
That one I am aware of, as language geek, I am always curious to GPU alternatives that aren't always the same old story only C and C++ get to party, which is actually an advantage of CUDA's polyglot approach.
Thanks for the heads up nonetheless.
Pompidou
Maybe codfns for apl will solve this ? That's what I understood.. but maybe I'm wrong.
fc417fc802
I am wondering about this as well. What is the gap between what you're envisioning and codfns?
kvdveer
The linked document only contains a warning about how versioning is weird, and a description of the syntax. No examples beyond trivial one-liners.
What problem is K trying to solve? What does a K program look like?
FjordWarden
I've only played around with k and APL in my spare time so I can't speak to real world problems. It is a ridiculously powerful query language, where in SQL you have only started writing `SELECT ...`, in k you are already done. But you need to have very good tacit knowledge of algorithms and the weird syntax to be productive, like oh I need to calculate an integral-image of this time-series, but that just a pre-scan over addition, boom and you are done. The theory of array programming with a focus in combinators is also an interesting perspective on functional programming. IMHO not something you should write full program in, but that hasn't stopped some from trying.
bee_rider
This was a helpful comment. After the article, the question that popped into my head was… so ok should I try and compare this to like BLAS or something like Jax?
But, this sort of language is more about writing and reading from the disk efficiently, right? I guess SIMD type optimizations would be less of a thing.
FjordWarden
I think that array languages have historically used memory mapped files for IO, and treat them like a big data frame, but other versions also support streaming IO. Its up to the implementers of the runtime to use SIMD instructions if they deem this optimal but not something you would use yourself.
rak1507
Personally I think the best comparison would be Python+Pandas/polars+... or R+tidyverse+..., the key thing being there's less need for the "..." in a language with good table manipulation etc built in.
Pet_Ant
I feel like measuring things in characters is not meaningful, but only in tokens. Replacing "SELECT" with "SEL" would not improve SQL in the slightest.
Thorrez
A one-liner in k tends to be equivalent to a much larger program in another language.
Here's a program in k. I'm not sure exactly what it does. I think it might be a json encoder/decoder:
saghm
It says a lot that the name of the file for is more informative about what the code does than the entirety of the file itself. "Readability is a property of the reader" indeed, but also the writer...
bregma
Dialup modems on a bad connection used to generate more readable code.
poulpy123
The problem solved by K is the long-term employment of people writing K. You can't be fired if you're the only one understanding more or less the codebase
dboreham
This is true about more software development than you realize.
bear8642
K is a fast vector language, used (primarily) for time series data analysis.
>What does a K program look like?
You might want to check out https://news.ycombinator.com/item?id=40335921
beagle3 and geocar both have various comments you might want to search for.
mananaysiempre
> a fast vector language
With an Oracle-style DeWitt clause[1] prohibiting public benchmarks.
[1] https://mlochbaum.github.io/BQN/implementation/kclaims.html
rustc
Shakti (the latest K implementation by the author of K) claims [1] to load a 50gb csv in 1.6 seconds which according to them takes 265 seconds with Polars. Has anyone independently verified these claims? Is Polars really leaving 2 orders of magnitude performance on the table?
[1]: https://shakti.com/ -> Compare -> h2o.k
vessenes
Some snark in here, I'll try and give it a fair shake. Whitney's site mentions '300 spartans' as the rough number of people using k, although it's probably more than that.
Two reasons k folks like k: first, if you believe that programmer working memory, as in the number of chars or lines of code you personally can hold in your head is limited, then it might make sense to be as terse as possible -- this will significantly increase the range of things you can reason about.
Second, if such a language were to focus more on array and vector-level manipulation, then for certain sorts of math tasks, you might be pretty close to grad student nirvana -- programming looks like using a chalkboard to work out a strategy for some processing, and then straightforwardly translating this strategy without mucking around with all the 100s of lines of weird shit say python or java make you do to process something in bulk and in parallel.
On top of this, whitney is a mad genius, and his k interpreters tend to be SCREAMING fast, and, like a couple of hundred kilobytes compiled. Over time the language has built connections to large-scale data processing jobs (as in, you run a microsend-or-shorter-timeframe strategy based on realtime depth data from 500 different stocks, say), and it has benefitted from the path dependence you get there.
Anyway back to the top - it exists as both a rallying cry for and a great tool for a certain sort of engineer that wants to make millions of dollars and refer to him/herself as a "Spartan" of coders.
reedf1
K solves the problem of bank account for two groups of people, kX Systems and quants.
sz4kerto
Absolutely not being sarcastic: one problem it solves is that it is very hard to read as a beginner, so it can be intimidating (although it becomes much easier to read a bit later). This, coupled with the general arrogance of k/q practitioners (again, not really saying this in a negative way) and that k, kdb, etc. deliberately doesn't give you guardrails makes people who write k/q seem a bit 'mythical' and make them feel very clever.
So I think k, q and kdb are fun to work with, but one of the major components of its success is that it allowed a community (in finance) to evolve that can earn 50-150% more than their peer groups who do the same work in Java or C++. 10 years ago a kx course cost $1500 per person per day.
pjmlp
To note that those are typical prices for enterprise level certifications, including some products that some Java or C++ devs might need to interact with, when working on those kind of environments.
cppandjava
Hmm. I work in finance writing C++ and Java and I doubt other people in finance make 50-150% more than me because they know `q`.
gitonthescene
I don't know. If you're writing Java you may not be working on the same types of problems.
null
sebg
A companion guide that I always recommend if interested in K is: Q for mortals, found here - https://code.kx.com/q4m3/
Note, from wikipedia: Q serves as the query language for kdb+, a disk based and in-memory, column-based database. Kdb+ is based on the language k, a terse variant of the language APL. Q is a thin wrapper around k, providing a more readable, English-like interface.
mwexler
Pulled from above:
Coding Style The q gods have no need for explanatory error messages or comments since their q code is perfect and self-documenting. Even experienced mortals spend hours poring over cryptic q error messages such as the ones above. Moreover, many mortals eschew comments in misanthropic coding macho. Don’t.
A more enjoyable read than the parent post.nialv7
There's also Nial: https://github.com/danlm/qnial7 which is (pardon the oversimplification) APL but with words instead of symbols.
steveBK123
A set of links with good examples of common problems solved in Q
https://code.kx.com/phrases/wikipage/
poulpy123
I'm somewhat convinced that there is a middle ground between corporate java and languages like K
jamal-kumar
I always thought it sounded super cool but it just doesn't exist in the problem spaces I work in. Like kdb+ was specifically designed to be run on bare metal without a full OS in the way of things going fast, and in quant environments where you're trying to shave off nanoseconds on the computations because your company's gone and invested in a dedicated fibre line to trading servers.
eudhxhdhsb32
That's actually not true at all. No one who cares about nanoseconds is using kdb+ for a production trading system.
It's primarily used for trading research and surveillance, not live trading. And I've never heard of anyone running it without an OS.
bear8642
> And I've never heard of anyone running it without an OS.
kOS is in development though current status is unknown.
(https://gist.github.com/chrispsn/da00835bb122c42f429a084df83...)
7thaccount
I think that got abandoned ages ago.
WorkerBee28474
> No one who cares about nanoseconds is using kdb+ for a production trading system.
For those curious, what they're actually using is FPGAs and custom silicon.
jamal-kumar
Super interesting thanks for the tidbit
tempodox
IDK, I'd rather have a language that compiles to native code, isn't quite as write-only as that, and doesn't cost an arm and a leg, even when using a DB.
blablablerg
"K is a general-purpose programming language that excels as a tool for data wrangling, analytics and transformation."
How does it compare to R/tidyverse?
7thaccount
It's mainly for quants where you couple the array language with a time series database of all your stock quotes. Once you understand the language you can do a ton of analysis with extremely little code. Think of it as a mathematical SQL dialect I guess.
In my opinion, it's very cool, but Python's ecosystem (and R's) is just so much better with scientific libraries and charting and all that. Kdb+ (the database) and K the language are likely much faster than R for general analysis type stuff. R is also free and Kdb+ is not.
IshKebab
> The same baseless accusations of “unreadable”, “write-only” and “impossible to learn” are leveled at all Iversonian languages, k included.
I'd be really curious to know if they really are baseless. It's very very difficult to imagine that K developers can really read a mess like this as easily as one might read Go or whatever.
https://github.com/KxSystems/kdb/blob/master/e/json.k
Has anyone tested this? Take a K program and ask a K developer to explain it? Or maybe introduce a deliberate bug and see how long they take to fix it compared to other languages. You could normalise the results based on how long it takes them to write some other code.
Free research project for any compsci researchers out there... (though good luck finding skilled K programmers).
geocar
> It's very very difficult to imagine that K developers can really read a mess like this as easily as one might read Go or whatever.
水落石出。
> Has anyone tested this? Take a K program and ask a K developer to explain it?
I am not sure what you're asking. Do you want me to read it to you?
Here is me reading some other people's code:
https://news.ycombinator.com/item?id=8476633
https://news.ycombinator.com/item?id=22010223
Do you want me to read to you the JSON encoder (written twice) and the decoder in this way?
> Or maybe introduce a deliberate bug and see how long they take to fix it compared to other languages.
https://news.ycombinator.com/item?id=27209093#27223086
> You could normalise the results based on how long it takes them to write some other code.
IshKebab
Thanks that was very interesting.
It seems to me that it has a lot of the same properties as regex. Looks like gobbledygook at first glance, but after learning it I can write them, and read them with some effort (depending on the complexity). However nobody would describe regexes as "readable", and they're quite error-prone. I definitely wouldn't want to write a whole program in regex.
Regexes shine most when they're used interactively, e.g. in one-off greps, or editors. There readability doesn't matter at all, error-proneness doesn't really matter, and terseness is important. The problems start when people put those grep commands in scripts where the output isn't supervised by humans.
I wonder if the same is true for K - it started as a query language for one-off queries & investigations, and then people started saving those queries and making bigger programs?
geocar
> However nobody would describe regexes as "readable"
I would, and do, and I urge you to be less judgemental about things you do not know anything about because you will never learn anything new with that attitude.
> I wonder if the same is true for K - it started as a query language for one-off queries & investigations,
Why do you wonder this? I don't think it's true, but so what? Did you not read what I wrote? Seriously: Why do you put so much effort trying to talk yourself out of learning how to do something that is obviously amazing to you?
I am telling you I can read this. I like this. I am not nobody, just someone you did not think existed. And I am telling you it is possible for you too.
michaelg7x
It's entirely possible, have done it at few times. For example, the `fby` verb[?] annoyed me one too many times, so I pulled it apart to see what was going on. In contrast to json.k it's quite short. I usually split each separable idea into a new line and introduce a bunch of new variables to track state that would otherwise be passed from right to left. Lengthy end-of-line comments are my chosen way of understanding q or k when I come back to anything later.
rak1507
You have been talking about array languages on HN for at least 6 years, and still refuse to believe that anyone can read them!
What do you have to gain from this stance, and why don't you believe people who tell you otherwise?
IshKebab
It's not a question of can they read them, it's are they readable. I obviously don't believe things just because people say them. Do you?
rak1507
When it comes to subjective opinions, what other choice do you have? Your idea of doing studies is interesting but that's not even been done for most languages, yet claiming "python is unreadable" would clearly be laughable.
Either everyone who uses array languages does actually find them readable, or they're all persistently lying for... what reason? And forcing themselves to use something they don't find readable? Why would anyone do that! Especially considering a lot of array language users are hobbyists, who have chosen to use them, it's not like they're forced to.
jbritton
code_report does a bunch of videos on this https://youtu.be/pq1k5USZZ9A?si=hmzucWWdNnGrI0Os
jbritton
Link to the video before the one above that compares APL, BQN, J, R, Julia, Numpy on the same problem. https://youtu.be/8ynsN4nJxzU?si=EeAZEZzA2kd0mw1y
hcfman
I build a language called K for my masters thesis in 1984. Who was first ?
mlochbaum
You win! Whitney was just out of graduate school at the time, and had worked some with APL at I.P. Sharp but was implementing "object-oriented languages, a lot of different LISPs, Prolog"[0]. Next was the more APL-like A around 1985 and K only in 1992.
Side note, but some people have such an evident talent for writing that it makes reading about _any_ topic a worthwhile experience. This author, Stefan Kruger, seems to be one of them.
I almost wish this link was to a blog rather than to a book about K, for which I only have a perennial curiosity.
Here's to hoping they consider writing said blog. I notice they have one but it only has 3 posts, all of which are about past Advent of Code puzzles.