Live data from Hacker News

The Zen of R

gist.github.com

1–10 of 28 posts

Re: The Zen of R

#3
I've often felt that there is a world of terse, clear code waiting to be unlocked in R, but haven't been able to find it myself. This is a great example.

Re: The Zen of R

#4
The most of this Zen comes from array paradigm, not functional; still it is nice to see another soul on the path to Renlightenment (-;

Re: The Zen of R

#5
post #4

The most of this Zen comes from array paradigm, not functional; still it is nice to see another soul on the path to Renlightenment (-;

That's a matter of perspective. Folds and scans exist for all regular data types, not only arrays, so I consider this a part of functional programming and type theory.

Here he is computing the history of states of a random walk as scan (*) initial updates. If you wanted to simulate branching random walks, you'd work over the data type of multiway trees instead of arrays, but the algorithm to compute the history of intermediate states would otherwise be identical, using the scan function for multiway trees.

Re: The Zen of R

#8

How did that take a couple months? Even in R's slightly awkward language, random walks shouldn't be very difficult! I'm baffled, I must be missing something.

"modifying it on and off as research questions changed": he wasn't just writing that code.

Re: The Zen of R

#9
In some ways this is better, and in others it is much worse. Using named constants instead of magic numbers, and breaking up complex logic into simpler named parts is a huge win for readability/maintainability, as any programmer quickly learns. The big one liner would be a lot nicer in about 3-4 chunks.

I’d rewrite this example as something like:

  num.steps 
[I’m not an R guy, so that might not be the most typical style ever, but you get the idea...]

Re: The Zen of R

#10

How did that take a couple months? Even in R's slightly awkward language, random walks shouldn't be very difficult! I'm baffled, I must be missing something.

Writing the code did not take him several months; that's just the period of time he utilized this code. During that time, he tweaked it for evolving requirements. What took a couple of months was the path to his epiphany.
Post reply on HN