PencilCoder

Script Recycling!

Goals:

  • Store reusable parts of your programs in separate files that you can easily import and run in any program whenever you need it

Coding Snippets:

  • coding snippets
  • CoffeeScript.load reads, compiles, and executes CoffeeScript code stored in a separate file named with a .coffee extension.
  • CoffeeScript.load executes the code in a nested scope. To make values from that nested scope available in the current scope, assign them to properties of the window object, as illustrated here with the custom print function.

Math and Computer Concepts:

  • Code reuse is central to efficient coding. Recall that functions facilitate code reuse by allowing us to reuse a block of code through a simple function call. Such code reuse reduces the potential for bugs and simplifies code maintenance. This lesson shows how to take this code-recycling to the next level, by making useful functions (and/or other code) readily available to any program we write.

Activities:

Save each of the following in a folder called ScriptRecycling.