Getting your pseudo-code straight

Having just graded 109 two-page pseudo-code answers, I am keenly aware that students have real problems keeping straight what variables hold what type of data. The problem was to augment a red-black tree keyed on date with an energy total, and then to walk the tree to determine an energy usage between two dates. I saw lots of code doing things like:

node.left += energy
node.key = energy
T.root = total

All three of those lines of code would destroy the red-black tree by wiping out one of its structural components with auxilliary data.

It occurred to me that it might be a good idea to have students begin their work by listing each variable they will be dealing with, and what sort of thing it will hold. Then, whenever they are about to assign to it, they can check back to the "pseudo-declarations."

But I haven't seen this taught. Is anyone familiar with a place where this is recommended?


Popular posts from this blog

Central Planning Works!

Fair's fair!

More college diversity and tolerance