Skip to main content
Teacher Portal

Evaluate and Explain

Teacher Toolbox icon Teacher Toolbox - Introducing Code Efficiency

Now that students have had practice writing code sequences to accomplish a specific task, they will be asked to apply those skills to reading code sequences and evaluating them. In this activity, students will be given a map similar to the one in the Play section, and asked to look at 3 code sequences to choose the preferred solution. For each sequence students will answer 3 questions:

  • Does this code accomplish the task?

  • If it works, what are the advantages of this code over the others?

  • What are the disadvantages of this code over the others?

Then, looking at all of the sequences, the students will be introduced to the idea of code efficiency and asked what their preferred solution is—based on efficiency and their own preferences—and to explain why. This can be a springboard for a whole class discussion about efficiency and accuracy in coding.

Reading Code Sequences to Choose a Preferred Solution

As your class worked on the Play section, you probably noticed that there were many different solutions to the same problem that was presented. That is something that happens often in the world of programming. While there can be different ways to do something, everyone will have a preferred method or solution, and that could be based on a number of factors. In this activity, your group will look at 3 possible code block solutions to a problem, figure out if they work in the intended fashion, then choose a preferred solution from the group and explain why you chose it.

The problem: Create a sequence that, when the robot begins at the Start, will travel into and out of all 3 classrooms (in any order) and return to the End point. The robot must navigate around the stairs, and can go through the doorways marked by the small rectangles on the map image.

Sketched layout showing the Start at the bottom left corner and the End at the bottom right corner. Above the Start is Room A with a doorway facing the start and one to the right, facing the stairs in the center. Directly to the right of the stairs are Room B and Room C stacked above the End. There are doorways to Rooms B and C facing the stairs, and one connecting the two.

  • For each solution below, answer these 3 questions in your engineering notebook:
    • Does this code accomplish the task? Why or why not?
    • If it does work, what are the advantages of this code over the others?
    • What are the disadvantages of this code over the others?
  • Most of the time, programming is evaluated on its efficiency, and the preferred solution is one that accomplishes the goal in the most efficient way possible.

Click on the solutions below to see a larger image.

Example solution for the challenge consisting of 19 Drive to and Turn for blocks connected to the When Started block. In order, the blocks will make the robot Turn right 90 degrees, drive forward 10 inches, turn left 90 degrees drive forward 3 inches, then reverse 6 inches, then turn left 90 degrees, drive forward 10 inches. Then turn right 90 degrees, drive forward 8 inches and reverse 4 inches, turn right 90 degrees, drive forward 10 inches. Then turn left 90 degrees, drive forward 1 inch, turn right 90 degrees, drive forward 3 inches and reverse 4, then turn right 90 degrees and drive forward 5 inches.
Solution A (inches)

An example solution with 11 Drive for and Turn for blocks connected to a When started block. In order the blocks will make the robot drive forward 10 inches, turn left 90 degrees, drive forward 1 inch, turn left 90 degrees, drive forward 1 inch, turn right 90 degrees, drive forward 10 inches, turn right 90 degrees, then drive reverse 5 inches, turn right 90 degrees and drive forward 10 inches.
Solution B (inches)
An example solution with 10 Drive for and Turn for blocks connected to the When started block. In order, the blocks will make the robot drive forward for 8 inches then 4 inches, turn right 90 degrees, drive forward 13 inches, turn left 90 degrees, drive forward 8 inches, turn left 90 degrees, drive forward 4 inches, turn right 90 degrees, and drive reverse for 5 inches.
Solution C (inches)
Example solution for the challenge consisting of 19 Drive to and Turn for blocks connected to the When Started block. In order, the blocks will make the robot Turn right 90 degrees, drive forward 254mm, turn left 90 degrees drive forward 76mm, then reverse 152mm, then turn left 90 degrees, drive forward 254mm. Then turn right 90 degrees, drive forward 203mm and reverse 101mm, turn right 90 degrees, drive forward 254mm. Then turn left 90 degrees, drive forward 25mm, turn right 90 degrees, drive forward 76mm and reverse 101mm, then turn right 90 degrees and drive forward 127mm.
Solution A (metric)
An example solution with 11 Drive for and Turn for blocks connected to a When started block. In order the blocks will make the robot drive forward 254mm, turn left 90 degrees, drive forward 25mm, turn left 90 degrees, drive forward 25mm, turn right 90 degrees, drive forward 254mm, turn right 90 degrees, then drive reverse 127mm, turn right 90 degrees and drive forward 254mm..
Solution B (metric)
An example solution with 10 Drive for and Turn for blocks connected to the When started block. In order, the blocks will make the robot drive forward for 203mm then 101mm, turn right 90 degrees, drive forward 330mm, turn left 90 degrees, drive forward 203mm, turn left 90 degrees, drive forward 10mm, turn right 90 degrees, and drive reverse for 127mm..
Solution C (metric)

What is Code Efficiency?

If you needed to get 3 things from your kitchen, you would probably go get all 3 things in one trip, instead of making 3 separate trips. Why? Because it would be more efficient. Efficient means “achieving maximum productivity with minimum wasted effort or expense.” So how does that connect to programming?

Code efficiency means that a program is written to work well and quickly, using the least amount of work, or steps, properly, while still doing its job. It is important because it reduces the risk of a program not functioning well, and in turn, causing problems for other parts of a program that are running around it. The efficiency of a code can be a measure of quality, and when we write projects in VEXcode IQ block, we are often looking for the most “efficient” project as the preferred solution.

Basically, code efficiency is a principle that means you want to write a code that accomplishes your goal using the fewest commands, or blocks, possible.

In your Engineering Notebook, answer the following questions:

  • With code efficiency in mind, which is your preferred solution and why?
  • Do you think that is the best solution, why or why not?

Teacher Toolbox icon Teacher Toolbox - Answers

Answers may vary since the no specific dimensions were given above for creating a sequence to navigate around three rooms.
Click here for a possible example solution.

Motivate Discussion icon Motivate Discussion

While efficiency is useful, we often have other considerations about how or why we do things a certain way. Have students share their answers in their Engineering Notebook, and/or use this question to frame a discussion about the balance of efficiency and actions.
Q: In programming, efficiency is usually the preferred methodology; can you think of a reason why this is the case?
A: Answers will vary, but some include:

  • Editing projects so that they are more efficient helps those in the future that could be possibly working with the same project. For example, if you work on a project and then a few days later, ask your friend to update the project and add a few more items to increase the functionality, it will be easier for your friend to read and work with if the project is written efficiently.

  • Projects are always susceptible to errors. The more efficient a project is written, the less likely of an error to be made.

  • Individuals who use programming to maneuver industrial robots rely on those projects being efficient in order to save the company time, energy, and resources.