2 ms·
Many people use descriptive variable names to carry semantic information. APLers use extremely consistent, stereotypical naming conventions which also carry se
by RodgerTheGreat 8y ago
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?
- theamk 8y agoI think the good rule of thumb is to have longer names in bigger scopes. So a variable for short loop or an argument to 1 line function can be single char, while arguments to medium length functions are a word, and globals (including functions) are one or multiple words. To get to your example, the preferred signature would be: square:{x*x}
- bakul 8y agoMost 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!