q is an interesting language and am using it for the advent of code. While the language superficially seems simple, it features a lot of hidden complexity and dubious design decisions. Every operator is massively overloaded on rank and type. There are functions that accept functions or lists or atoms as arguments: supposedly there’s supposed to be mathematical commonality, but coming from the statistically typed FP world, this kind of polymorphism makes me extremely uncomfortable.

The dynamic typing bugs me as well, it would really help to have an editor be able to tell ahead of time whether an expression is valid.

Speaking of valid code, the error messages are absolutely terrible and stink of arrogance. I’m talking about ed level error messages: no words, no pointing out the error, just some one letter message that is supposed to indicate a type or function argument error.

A lot of the culture of the language is built in Arthur Whitney’s own image: error messages are bad, comments are for stupid people, white space is for “Qbies”

Speaking of cultural, the jargon of the language is didactic and annoying. All over the documentation references to monadic or niladic or diadic functions. Also calling things verbs or adverbs or nouns is annoying and unhelpful. Even in the book “Q for mortals” the author prizes using different terminology than literally anyone else and strikes me as trying to be deliberately obtuse. He even spends an entire chapter talking about the mathematical nature of natural numbers, which strikes me as both unhelpful and narcissistic.

Going back to the language, not only are functions overloaded to a ridiculous level, but the syntax of the language itself is inconsistent. Multiple ways to call a function, all in the name of reducing unnecessary typing. Also the syntax and name of some functions strikes me as very add: ‘/‘ is not used for division, but instead for both comments and folds. ‘,’ is used for appending lists, while ‘;’ is used to separate function parameters. Instead of parents, Q uses ‘[]’ for function parameters. Here’s an example of finding the square of the hypotenuse in idiomatic q:

pyth_sq:{x^2+y^2}

One can use xyz without explicitly declaring them as parameters, which is both nice and arbitrary. I would much prefer to have something like Scala’s underscore or maybe something like _1,_2,... Here’s the function written with explicit parameters:

pyth_sq:{[x;y]x^2+y^2}

Personally I think a syntax (and spacing) like:

pyth_sq = { (x, y) => x^2 + y^2 }

would be nicer.

While the naming of the functions and syntax is arbitrary, I beginning to understand the rational and design of the language. For Whitney, code is the root of all evil: less code, less bugs. Also less code, the more you can fit in your head. This is the reason why everything is overloaded I think: because Whitney ran out of ASCII symbols and didn’t want to use names (more information to remember).

Regardless, the real reason people use q isn’t because of the language, it’s often despite of it. The kdb+ database and q sharing the same memory space is the real advantage. The performance of the system is so exceptional that a single server can outperform even a large Hadoop cluster: the code is out of this world optimized.

I’ve began to think that q is a natural and easier to use extension of Chuck Moore and Forth’s philosophy and language. The languages both share the same tenets of performance, terseness, and minimal syntax. While forth works on a fixed number of stacks, q works on a arbitrary number of n-dimensional vectors, a natural extension to the one dimensional stack.

Anyways, sorry for the rant. I’m still learning q so take what I say with a grain of salt. I can imagine an expert q developer becoming extremely productive and comfortable: I’m personally just not there yet. When I finish advent of code, I’ll have a better perspective.