2, ఏప్రిల్ 2014, బుధవారం

Programming Concepts for the Humanities: Recipes





It is helpful to think about programming as a set of very specific instructions, like the ones that come on the back of a shampoo bottle, except even more fleshed out and more specific — if you tell a computer to “lather, rinse, repeat” then it will be stuck in an infinite loop. You would have to really break it down and instruct the computer to wet its head with some water first, then pick up the shampoo bottle, open the lid of the bottle’s cap, squeeze some shampoo out, etc.

Recipes are a great textual form for thinking about programming in a real-world context, since they supply specific instructions. In foreign language classes, recipes are an engaging way to get students interested in language-learning, especially if they get to eat the spoils that come with recipe preparation! Recipes can also engage the budding computer programmer who may be used to Humanities coursework.

Google, known for infusing fun into its brand, has supplied this Google Talk Support page, How to make AWESOME guacamole!, which instructs how to make guacamole with some JavaScript instead of pure natural language:

Don’t be fooled, guacamole is both healthful and delicious, AND - for a limited time - we’re sharing our AWESOME implementation with YOU!
Ingredients
Let person_count be the number of people snacking on your dip. Then…
  • avocado_count = Math.max(person_count, 4)
  • tomato_count = Math.ceil(avocado_count / 3)
  • onion_count = Math.floor(tomato_count / 2)
  • jalapeno_count = Math.ceil(onion_count / 2)
  • cilantro_leaf_count = avocado_count * 10
  • salt_grain_count = avocado_count * 100
  • lime_count = Math.ceil(avocado_count / 4)
Steps
  1. Instantiate a large bowl
  2. Peel avocados, remove pits, and add to the bowl
  3. Dice tomatoes, onions, and jalapenos and add to the bowl
  4. Chop cilantro leaves and add to the bowl
  5. Add salt grains to the bowl
  6. Slice / squeeze limes and add emptied juice to the bowl
  7. Instantiate two large spoons
  8. Gripping one spoon in each hand, mash ingredients in the bowl together until a smooth consistency is obtained (note: mashing action should reflect the sound of a galloping horse)
  9. Serve with your favorite bag of tortilla chips
  10. Enjoy :)

Interestingly, the instructables on How to write useful programs in Java also uses recipes as a metaphor. The Guacamole, for example, would be written down step-by-step (methods) and then that would be its own class, which can be called up by, say, the Burrito class. That way, the programmer would only need to write the instructions (recipe) for the Burrito, without having to write the instructions for the Guacamole again.

   

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి