Top Links
Logo
 

 

Writing code: The logic and the language

$ld = $naid % 10;

if ($ld >= 0 && $ld <= 4) {

$quid = oldmethod($topicselected);

return $quid;

}

else

{

$quid=pastperform($topicselected, $naid);

return $quid;

}

Here is a short snippet of code included in the program that runs one of my experiments. The experiment contrasts two methods for presenting college students online study questions. The code may first appear to be gibberish, but if I provide you a little more information you should be able to follow the logic. The purpose of this code is to assign students to one of two groups so that one group receives questions selected at random (oldmethod) and the other group receives a question from the same category after answering a question incorrectly (pastperform). All you see here is how the students are selected in order to receive a question using one approach or the other.

The first line of code takes a student's ID number, chops off the final digit, and assigns this digit to the variable ld. The rest of the code does one thing if this digit is between 0 and 4 and a different thing if the digit is between 5 and 9. Note that you do not see the actual selection of those cases that fall between 5 and 9 because these values would be all the remain if the value was not less than 5. Hence the program says, if the student is not in this group, the student must be in the other group.

The details of what happens depending on this grouping is determined elsewhere in the program, but this snippet says find the number of the next question to ask ($quid) in one method or the other depending on which group the student is in and then send this question number back so the question can be selected and displayed.

It might be helpful to think about this example on two levels. There is a level that might be described as the logic of the task. How would you assign a group of individuals identified by a multi-digit number to two groups? Then there is the level that represents the code used to explain to the computer how to implement the logic. The language used here is called PHP. While this language is not regarded as overly complicated, you can see that it is precise. There are symbols (brackets, semicolons, dollar signs) that must be used precisely. Forget a symbol and the program will generate an error message or generate an unexpected result rather than do what the programmer expects.

There are possible educational benefits in both levels. Learning to think and solve problems in the logical way required to program is argued to have general value in many disciplines. We discuss the multiple values of what is now often called computational thinking at another place in this chapter. Of course, the vocational and other applied benefits of programming do not occur unless a learner is capable of translating logic into code. The concern is that if mastery of both level is required, students may become frustrated by the demands of learning the syntax and commands of a programming language and give up before they give coding a serious chance. We provided the snippet of code we used to initiate this section to get you to recognize a few of the details a programmer might have to learn. What if students could be provided coding experiences that did not require they master the details of the strange punctuation and syntax? One current approach is to use a visual programming method based on what might be described as icons or graphic symbols.

This chapter nearly ignores the full-length computer science courses asking that students develop proficiency in a “programming language” to concentrate on what might be described as introductory coding experiences. This position is consistent with the general approach we take regarding any given content area; e.g., biology, chemistry, history. We attempt to explore contributions technology might make in multiple disciplines and offer a few examples of such applications, but leave the development of disciplinary expertise to others. We feel no more capable of developing full awareness of what would go on in a computer science class than in a chemistry class. Our intent is to raise awareness. One of the advantages of this perspective is that we can involve you directly. We intend that you explore some of our examples yourself using free or inexpensive software and perhaps some of you would find reason to incorporate projects based on such software in your classroom. Most of our examples will focus on the LOGO programming language. LOGO has been around for a while, is still available, and popular capabilities can still be found embedded in free or inexpensive software you can access.

Return to resources

 
About | Outline | Copyright
about.html outline.html copyright.html