June 2025
Intermediate to advanced
152 pages
3h 15m
English
| Practice 20 | Let the Data Do the Driving |
Replacing code with data is probably at the top of the list of things that give me that self-satisfied feel-good feeling when I code.
I love taking code that is either repetitive or close to being repetitive and shrinking it all down to a single function that can be parameterized by data.
Why? Because…
| Idea 46 | Data is easier to change than code |
Maybe I’m creating a bunch of shapes for a drawing program:
| | shape = add_shape(Triangle, sides: 3) |
| | shapes_by_sides[3].push(shape) |
| | |
| | shape = add_shape(Square, sides: 4) |
| | shapes_by_sides[4].push(shape) |
| | |
| | shape = add_shape(Rhombus, sides: 4) |
| | shapes_by_sides[4].push(shape) |
| | : : |
I’d most likely write the code this way when I start with the first shape and stick with ...
Read now
Unlock full access