4 ms·
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 d
by smabie 7y ago
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.
- yiyus 7y ago> 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. That is a valid opinion, but this is not a k thing. The same jargon is used by APL, J and practically any other array programming language. In fact, the term monad was first used in this context [1]. [1] https://en.wikipedia.org/wiki/Monad_(functional_programming)#History https://en.wikipedia.org/wiki/Monad_(functional_programming)...
- anonu 7y agoInteresting rant. Your function pyth_sq:{x^2+y^2} should be pyth_sq:{(x xexp 2)+y xexp 2}. While you're right about all the idiosyncrasies with the overloading and error messages, they tend to melt away when you get a hang of it. The language is only partly the cool thing. The real power of Kdb is, IMHO, the ability to quikly get a distributed "app engine" on it's feet. App engine with hot code swapping and 0 downtime.
- SifJar 7y ago> 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. For what it's worth, Kx appears to agree & have been updating their documentation to try & use more "familiar" terminology for these things; monadic/niladic/diadic & noun/verb/adverb are all going away. There'll still be a lot of older stuff scattered around the web with the old terms, but an effort is being made