Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I love mike bostock's stuff, but his code often makes me feel sorry for whoever has to deal with his code after him

   // Pick a location that’s not yet in the maze (if any).
    do if ((index0 = remaining.pop()) == null) return true;
    while (cells[index0] >= 0);

    // Perform a random walk starting at this location,
    previous[index0] = index0;
    walk: while (true) {
      i = index0 % width;
      j = index0 / width | 0;

      // picking a legal random direction at each step.
      direction = Math.random() * 4 | 0;
      if (direction === 0) { if (j <= 0) continue walk; --j; }
      else if (direction === 1) { if (j >= height - 1) continue walk; ++j; }
      else if (direction === 2) { if (i <= 0) continue walk; --i; }
      else { if (i >= width - 1) continue walk; ++i; }
note the braceless do while and the labeled jump statements


Those labelled jumps are equivalent to common unlabeled continues, but safer.

The braceless do-whiles are isolated by blank lines and have leading comments.

I'd prefer bostock's code over the average uncommented code with cryptic abbreviated var names.


These would basically be "time for serious feedback" at any place I've worked in the last 25 years.

Seriously, the style is going to generate errors.


so bostock has gotten better, but there was a time (also known as when I did a lot of stuff with topojson and unraveled how it worked) where it looked like this https://github.com/mbostock/topojson/blob/fe691fc61c38a79b09...


Yep, I just a couple of hours messing around with it and got tripped up many times by this stuff.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: