Karel: Solutions to problems

Solution to programming errors

Start of task End of task

   BEGINNING-OF-PROGRAM  
      BEGINNING-OF-EXECUTION  
         move;
         pickbeeber;     * misspelled word (lex. error)
         turnleft;
         putbeeper       * no semicolon (synt. error)
         move            * forgot turnoff instruction (synt. error)   
      END-OF-EXECUTION
   END-OF-PROGRAM        * error of intent
   
   * error of intent: If the errors were fixed, Karel would still
     deposit the beeper where it was, not one block to the left.

Discussion of Program 1

This program is correct and works (after the dots are filled in, of course). However, it is very difficult to take a quick look at the program and decide what it is doing. It is unreadable

It is easy to forget one of the instructions, in which case the whole program would either lead to an error shutoff or to an intent error. However, it would be difficult to find the missing (or superfluous) instruction. It is hard to debug

If, say, another row of beepers grows overnight, this program would need a whole slew of new instructions. It is difficult to extend

Discussion of Program 2

After filling in the definitions for the new words, this program will not necessarily shorter than program 1. However, it seems easy to see what is going on, even if you are not an expert in robot programming. It is easy to read

If one of the instructions does not work, we can concentrate on fixing it. Once it is fixed, it will continue to work correctly at every point where it is used. However, it still has two instructions that basically do the same thing, namely go-to-next-right-row and go-to-next-left-row. That might lead to confusion as to which of these to use. It is easier to debug that program 1, but not perfect

If, say, another row of beepers grows overnight, this program could very easily be modified. Just add a couple of lines and those rows will be harvested as well. It is easy to extend

Discussion of Program 3

After filling in the necessary definitions of the new instructions, this program may not be shorter than either of the other programs. However, it is clearly easy to read, even for a non-expert in robot programming. It also uses very few, simple new instructions, and it is not hard to decide that everything is at the right position. If one of those instructions works right, it will always work correctly. Therefore, the program is easy to debug

If, say, another row of beepers grows overnight, this program could not handle it easily. But if two rows would grow, it would again be easy to modify the program to handle that sitution. Therefore, the program is as flexible as program 2

(bgw)