What is a computer program?

As I gather the data needed to create the fourth and final table for the Flock app – which also happens to be the table with the most foreign keys, being the table which links all the other three – I am re-reading the excellent (and free!) Eloquent JavaScript. It is extremely concise, and the integrated coding fields to try practice problems or just tinker with examples is just awesome.

Not being a CS major, my way into code and the ways of programming has been iterative and, well, circular. From what I’ve gathered, this is not only not unusual it is instead “the way it is.” To this point, in the introduction to EJ, Haverbeke presents a primitive program that finds the sum of the numbers from 1 to 10. In my own words, this is how the program works:

  1. Assign the number 0 to location 0. (This is our sum.)
  2. Assign the number 1 to location 1. (This is our count.)
  3. Assign the value of location 1 to location 2. (This is our test.)
  4. Subtract 11 (the upper limit of the range + 1, so if we were looking for the sum of the numbers between 1 and 100, this would be 101) from the value of location 2. (This establishes whether or not we’ve reached our upper limit.)
  5. If it is true that the value of location 2 is now 0, go to step 9. Otherwise proceed to step 6. (If it is 0, we’ve summed all needed digits and should stop and simply return the value of location 0, or step 9.)
  6. Add the value of location 1 to location 0. (Our sum-finding action.)
  7. Add one to the value of location 1. (This advances our count. The sum-finding action should only run as long as the count is less than or equal to our upper limit.)
  8. Repeat steps 3 through 7 until 5 is true.
  9. Return value of location 0. (It’s 55.)

Again, not being a CS major – an English major with a Master’s degree, in fact! – wrapping my mind around this very simple program was a bit of an “A-HA” moment. If there is one thing I can say I absolutely enjoy about programming is that feeling of progress; the insight is real, and things you learn make it possible to learn more things in an almost exponential way. Seeing the results of learning to code means feeling the power of programming – until next time!


Posted

in

by

Tags: