What about K?
107 comments
·February 10, 2025airstrike
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.
bear8642
The about section has links to other things he's written/presented.
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
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.
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!
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...
Pompidou
Maybe codfns for apl will solve this ? That's what I understood.. but maybe I'm wrong.
fc417fc802
[dead]
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?
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.
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.
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.
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
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.
null
swiftcoder
This is kind of the problem with every introductory text to an APL-family language.
I get the idea that one either already knows one needs an array programming language, or doesn't grok why anyone would need one
poulpy123
I'm somewhat convinced that there is a middle ground between corporate java and languages like K
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.steveBK123
A set of links with good examples of common problems solved in Q
https://code.kx.com/phrases/wikipage/
nialv7
There's also Nial: https://github.com/danlm/qnial7 which is (pardon the oversimplification) APL but with words instead of symbols.
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.
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.
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.
jbritton
code_report does a bunch of videos on this https://youtu.be/pq1k5USZZ9A?si=hmzucWWdNnGrI0Os
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.
sl0thentr0py
i've been doing the last 3 years advent of codes in q/kdb+, it's a lot of fun https://github.com/sl0thentr0py/aoc/blob/main/aoc2023/3/foo....
shric
My first thought was "weird, they made a language called k even though there is already a language called K". I then realized it's actually talking about K.
Thoroughout the article it's spelled k consistently except at the start of a sentence. This is weird. The language is K not k. Nobody spells the C language as c.
cess11
It's actually rather common to spell its as k, as well as K. I think q is more common than Q.
Implement all this jazz with s-expressions and I am on board!