Comment

Comment by jacobolus

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 <- 1000
  num.walks <- 100
  step.std.dev <- 0.03
  start.value <- 15

  rand.row <- function() rnorm(num.steps, 1, step.std.dev)
  walk <- function () cumprod(rand.row()) * start.value
  all.walks <- t(replicate(100, walk()))
  plot(colMeans(all.walks), type = "l")
[I’m not an R guy, so that might not be the most typical style ever, but you get the idea...]
parent jacobolus 14 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton