I'm James Hague, a recovering programmer who has been designing video games since the 1980s. This is Why You Spent All that Time Learning to Program and The Pure Tech Side is the Dark Side are good places to start.
Where are the comments?
Another Programming Idiom You've Never Heard OfNew programmers quickly pick-up how array indexing works. You fetch an element like this:
array. (More experienced folks can amuse themselves with the equally valid
3[array]in C.) Now here's a thought: what if you could fetch multiple values at the same time and the result was a new array?
Let's say the initial array is this:
This may seem like a frivolous extension to something you already knew how to do, but all of a sudden things have gotten interesting. Now indexing can be used for more than just indexing. For example, you can delete elements by omitting indices. This drops the first two elements:
In J, there's an operator that's like a sort, except the result specifies a permutation: a list of where each element should go. Using the same "10 5 9..." array, that first element should be in position 4, the value 5 should be in position 1, and so on. Here's the whole array of permuted indices.
(If you liked this, you might enjoy the original A Programming Idiom You've Never Heard Of.)