Easier Coding Assignment Creation with Solution Templates & Code Freezing

11:00 AM on October 6, 2022 | Product News computer science programming autograding

When testing auto-graded coding assessments, it’s easy to forget to remove the solution code from the starter code file before publishing.

Then, with one click, students have a fully completed coding assessment! This becomes even more likely when you go back to check old assignments or have newer authors, such as TAs, helping build the course. Now, Codio lets you automatically use Solution Templating to remove solutions from starter code files.

Additionally, when authoring coding assessments, it is common to want code inside the student's file that interfaces with auto-graders that you don’t want students to change. While surrounding the code with DO NOT EDIT comments helps – Codio now lets you freeze lines of code so students cannot edit them.

Solution Templating: Automatically Remove Solutions from Starter Code Files

To indicate where a solution is within a code file, simply add a ‘Codio Solution Begin’ comment before the solution lines and a ‘Codio Solution End’ comment at the end of the solution lines.

def main:
    # CODIO SOLUTION BEGIN
    print('Hello world!')
    # CODIO SOLUTION END

When the assignment is published, the student sees the following in the code file:

def main:
    # WRITE YOUR CODE HERE

While the above example is in python, solution templating works in a variety of languages:

  • C / C++
  • Java
  • Python
  • HTML / CSS / JS
  • Ruby
  • SQL
  • OCaml
  • PHP
  • Scala

You can see the complete list of file extensions supporting solution templating in our documentation.

Solution templating can be used more than once in a file – for example, if you want students to complete a number of Java methods but you want the method headers declared for them:

public class Driver {
 
  // Instance Variables
  String name;
  String ID;
 
  public Driver(String fullName, String licenseID) {
      // CODIO SOLUTION BEGIN
      name = fullName;
      ID = licenseID;
      // CODIO SOLUTION END  
  }
    public void setName(String newName) {
      // CODIO SOLUTION BEGIN
      name = newName;
      // CODIO SOLUTION END
  }
 
  public String getName() {
      // CODIO SOLUTION BEGIN
      return name;
      // CODIO SOLUTION END
  }
 
  public String getID() {
      // CODIO SOLUTION BEGIN
      return ID;
      // CODIO SOLUTION END
  }
}

 

When the student opens the assignment, they see:

public class Driver {
 
  // Instance Variables
  String name;
  String ID;
 
  public Driver(String fullName, String licenseID) {
      // WRITE YOUR CODE HERE
  }
    public void setName(String newName) {
      // WRITE YOUR CODE HERE
  }
 
  public String getName() {
      // WRITE YOUR CODE HERE
  }
 
  public String getID() {
      // WRITE YOUR CODE HERE
  }
}

 

It is important to note that the publishing process removes these solutions – so when teachers and TAs are in a student’s assignment to provide help or grade, these solutions will not be visible.

To provide a solution or any other help or grading information to teachers or TAs within a student’s assignment, you can use a guidance call-out block or a separate teacher-only page.

Freezing Lines of Code so Students Cannot Change Starter Code

When using Codio’s script-less code auto-grader, code is frequently included as part of the starter code to parse keyboard input or command line arguments into a student-ready format. Currently, many content authors try their best to clearly communicate not to edit this code to the student through comments:

//DO NOT EDIT////////////////////////////////////////////
  public static void main(String[] args) {             //
    ArrayList<String> list = new ArrayList<String>();  //
    for (String s : args) {                            //
      list.add(s);                                     //
    }                                                  //
    reverseSelectionSort(list);                        //
    for (String s2 : list) {                           //
      System.out.println(s2);                          //
    }                                                  //
  }                                                    //
/////////////////////////////////////////////////////////

Instead of relying on students reading and following directions, teachers can now freeze lines of code that the auto-grader relies on. Similar to Solution Templating, simply add a ‘FREEZE CODE BEGIN’ comment before the lines to be frozen and a ‘FREEZE CODE END’ comment at the end of the lines to be frozen. The example above would then look like this:

// FREEZE CODE BEGIN
  public static void main(String[] args) {            
    ArrayList<String> list = new ArrayList<String>(); 
    for (String s : args) {                           
      list.add(s);                                    
    }                                                 
    reverseSelectionSort(list);                       
    for (String s2 : list) {                          
      System.out.println(s2);                         
    }                                                 
  }                                                   
// FREEZE CODE END

 When students open their assignment, the frozen lines of code are both clearly indicated and un-editable:

While the above example is in Java, freezing lines of code works with a variety of languages:

  • C / C++
  • Java
  • Python
  • HTML / CSS / JS
  • Ruby
  • SQL
  • OCaml
  • PHP
  • Scala

You can see the complete list of file extensions supporting freezing lines of code in our documentation.

You can also have multiple sections of frozen code within the same code file. For example, you can freeze the entirety of the starter code:

// FREEZE CODE BEGINS
import java.util.Scanner;

public class Test{

public static void main(String args[]){
 
  Scanner input = new Scanner(System.in);
  //FREEZE CODE ENDS



 
// FREEZE CODE BEGINS
} // closes main method

} // closes Test class
// FREEZE CODE ENDS

 

When the student opens the assignment, they see:

Better Together: Combining Solution Templating and Code Freezing

Solution templating and code freezing can be combined in a single code file to ensure that the solution does not get passed to students and that students do not edit code that connects to the auto-grader. For example:

#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
// FREEZE CODE BEGIN
int num = stoi(argv[1]); // typecast the string to an int
// FREEZE CODE END

// CODIO SOLUTION BEGINS
cout << num * 3;         // print the int multiplied by 3
// CODIO SOLUTION ENDS

return 0;

}

Will be presented to the student as follows:

 

 

 

Elise Deitrick

Elise is Codio's VP of Product & Partnerships. She believes in making quality educational experiences available to everyone. With a BS in Computer Science and a PhD in STEM Education, she has spent the last several years teaching robotics, computer science and engineering. Elise now uses that experience and expertise to shape Codio's product and content.