3 ms·
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
by cwmma 13y ago
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
- judk 13y agoThose 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.
- kabdib 13y agoThese 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.
- cwmma 13y agoso 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/fe691fc61c38a79b093807bd86117e5d13a0d38c/lib/topojson/topology.js https://github.com/mbostock/topojson/blob/fe691fc61c38a79b09...
- IneffablePigeon 13y agoYep, I just a couple of hours messing around with it and got tripped up many times by this stuff.