Code to Joy by Michael Littman

Code to Joy by Michael Littman

Author:Michael Littman [Littman, Michael]
Language: eng
Format: epub, mobi
Tags: Computer programming; artificial intelligence; machine learning; social media; Computer literacy; Future of computing; Usability.
Publisher: MIT Press
Published: 2023-09-13T00:00:00+00:00


6

Consolidating into Loops

You Don’t Have to Tell Me Twice

Whether it’s in your hairstyle, your model airplane flying, or your cereal bowl, loops make an exciting addition. Your vocabulary for conveying tasks to a computer is no different.

A loop is a set of instructions or behaviors that is repeated multiple times. The most obvious advantage of communicating tasks using loops is that you can say a lot with very few words. Imagine you are in gym class and the instructor says you need to do a pushup, a pushup, a pushup, a pushup, a pushup, rest for a moment, then do a pushup, a pushup, a pushup, a pushup, a pushup, rest for a moment, then do a pushup, a pushup, a pushup, a pushup, a pushup, and stop. Phew! The effort it took to listen to the instructions left you too tired to actually do the exercise. A more parsimonious way to express this sequence would be for the trainer to say “Do three sets of five pushups.” As the number of sets and reps (repetitions without a break) grows, the number of saved words grows exponentially.

Being able to convey a long activity in very few words is nice in and of itself, but there’s a bunch of other advantages that come along with it. The shorter sequence is easier to remember, easier to follow, and easier to modify. It calls out the common structure in the sequence, which makes it easier to carry out the activity with less attention to the details.

Ikea, the Swedish furniture company famous for do-it-yourself assembly and meatballs, puts a lot of effort into flagging repetitions in its instructions. In the manual for its Hemnes eight-drawer dresser, it show a picture of the reverse of the piece of furniture with a whole bunch of nails standing at the ready to hold the backing board in place. But how do we secure these nails? Ikea provides a little diagram of a hammer hitting a single one of the nails into place. Should we just hammer in that one nail? No, the hammer is shown in a little speech bubble, which carries the notation “28x.” It’s telling us that we should repeat this hammering action for all twenty-eight of the nails shown. If Ikea hadn’t provided the “28x,” it might not be clear that this action should be repeated. But if it had drawn twenty-eight hammers on the diagram, it would have been cluttered and would oblige the customer to look at each of the twenty-eight pictures to see if there was some important difference. Not expressing the looping behavior explicitly makes a complicated process much, much worse.

As with the sets-reps example above, Ikea sometimes makes use of nesting, loops within loops. To walk us through attaching the drawer pulls on the Hemnes, Ikea shows a picture of a screwdriver twisting a screw into the knob to link them together. As in the nail example, the screwdriver-knob-screw group has a bubble around it with a “2x” label, indicating we need to repeat that action for the two knobs on the drawer.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.