4 ms·
The point wasn't to come up with the best api, but to illustrate how to format code that has repetitions and regular variations in it, to make it easy to visual
by DonHopkins 11y ago
The point wasn't to come up with the best api, but to illustrate how to format code that has repetitions and regular variations in it, to make it easy to visually identify which parts repeat and which parts vary. That makes it easier to read the code and spot errors.
For example:
sqrt((x * x) +
(y * y) +
(z * z));
You can run your eyes up and down each column to verify it's squaring x, y and z.
That reflects the structure and symmetry of the expression better than:
sqrt((x * x) + (y * y) + (y * z));
Did you spot the error?
sqrt((x * x) +
(y * y) +
(y * z));
How about now?
Here's some code that has a lot of examples of that style, a JavaScript implementation of a weird hybrid Margolis cellular automata neighborhood, which has a lot of two-dimensional patterns:
https://github.com/SimHacker/CAM6/blob/master/javascript/CAM6.js#L4282 https://github.com/SimHacker/CAM6/blob/master/javascript/CAM...