Perl programming: follow-up from Sept 29
Tutoring math or sciences, you need to remind your students to “show their work.” The tutor observes the same precedent in computer science.
Back in my last article, I discussed the changes to the Perl compound interest calculator so it could cover all the compounding possibilities. Though it accomplished its objective, that discussion left some loose ends, one of which I’ll attend to now.
Issue 1: Notice the “#” sign in the sixth line of code:
$ppyear=$ARGV[3];#compounding periods per year
Normally, you can’t just add text to a computer instruction and have the program still work. However, in Perl, “#” means “comment”: following the “#” sign, the rest of the line will be ignored by the computer.
Comments are used to tell the reader the functionality of lines of code. In the example above, $ppyear=$ARGV[3]; introduces a new variable. The comment after the “#” tells its purpose.
Even with small programs, the functionality of certain lines may be hard to decipher at a glance – even for the author of the code! If a few weeks have passed since you’ve looked at your program, you might not easily recall what a given line does. Part of the skill of programming is knowing what lines need to be explained, as well as how to explain them concisely with little comments. Even one or two good comments can make a program much easier to understand at a glance.
Putting the discussion into scholastic perspective, comments are how programmers “show their work.” Showing one’s work is really about explaining the ideas behind what’s written down. When the ideas are known, marks can be easier to give – and programs can be easier to fix. When you’re unsure of what you’re doing – that can be the best time to offer explanation:)
Source: Robert Pepper’s Perl Tutorial.
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.
Leave a Reply
You must be logged in to post a comment.