I'm preparing some exercises to introduce software developers who have no experience with Scheme to the language. Part of the exercises are simple things like:

Create a function that squares a number passed to it

I've been sort of debating whether or not I should include answers to the exercises or if I should provide them as a separate document. I think it would help the students to be able to examine one approach to doing this--a reference implementation as it were. But I do have some concerns about the students not even trying to do the exercise themselves before looking at the answers.

Should I provide answers to the exercises? If so should I include them as a part of the document with the exercises or as a separate document?

I realize this is a vague question so if I need to narrow it please just tell me. I can't think of a less generic way to ask the question right now.

  • $\begingroup$ No worries, this is a great question. And I'm very interested to see the answers, because I've struggled with the same thing. $\endgroup$ – Ben I. Mar 16 '18 at 18:43

I post solutions after the due date of an assignment. And usually, I'll go over them in class as well.

Two birds...

  1. Students get to see at least one working solution, although I try to come up with several.

  2. Posting the solution serves as a good block to students asking to turn in assignments late. They'll understand pretty well that they can't turn it in late after I've already posted solutions.

I've been trying this year to make videos of me working through the problems. Sometimes they'll be screencasts of me working through the problem in front of the class. Sometimes they'll be a little more scripted and recorded when there aren't students listening. Usually it's the shorter problems where I'll just record myself during class and the longer ones that I script out a bit.

Another activity I like is to do code reviews. I'll screen shot several student submitted solutions and we'll go over them anonymously. I'll include a couple that are really good solutions. But, better than that, I'll also include a few that are really close but not quite a working solution.

On some assignments, especially those that are a little more difficult, I'll provide a pseudocode algorithm with the assignment as a bit of a cheat sheet. Nothing that can be just typed in, but sometimes students need a little bit of a nudge in the right direction.


Don't provide code dumps. Provide guides that outline the process of solving the problem.

Create a function that squares a number passed to it

Don't just give out a fully-coded solution. The answer to this question is not as simple as regurgitating the syntax. It's a process of breaking the question down into smaller steps and taking those steps on one at a time.

It might start like this:

When you encounter a question like this, you might start by breaking it down into its individual parts.

  • We know we need to create a function.
  • We know the function needs to take a numeric argument.
  • We know the function should return the square of the number passed into it.

And if the students are writing and running the code, it might continue like this:

Now that we have these steps written down, we can start implementing them one at a time. Let's start by creating a function:

public void square(){

We might run this function to double-check that it's working how we expected. Next let's add an argument:

public void square(int number){
  System.out.println("number: " + number);

Finally, let's add a return type to the function and return the square of the number:

public int square(int number){
  return number * number;

Or if students are writing their code down on paper, it might look like this:

Start by writing the function definition. We know it needs a numeric return type and that it should take a numeric argument:

public int square(int number){

Next, we need to create the square of the number:

  int numberSquared = number * number;

Finally, we need to return this value:

return numberSquared;

Putting it all together, it looks like this:

public int square(int number){
  int numberSquared = number * number;
  return numberSquared;

Just giving out a full code solution doesn't really help with the actual process of writing code, which is what you're actually teaching.

  • $\begingroup$ I'm not discussing code dumps. I'm discussing giving the students one possible answer to the exercise I've given them. While I appreciate all the effort you put in to preparing your answer you've sort of misread my question. $\endgroup$ – Onorio Catenacci Mar 19 '18 at 12:38
  • $\begingroup$ @OnorioCatenacci And I believe you've misread my answer. By "code dump" I simply mean handing them a code solution without any explanation. The point I'm making in this answer is that the code is the least important part. The most important part is outlining the process of coming up with an answer in the first place. $\endgroup$ – Kevin Workman Mar 19 '18 at 16:12

To give or not to give, that is the question

There are actually several possibilities that reflect how you want the provided solution to be used. For context, I am an instructor at Colorado State University and I am discussing assignments that students might encounter in the first two to three years (not CS1).

Don't ever give the students solutions

The motivation for this approach is that one can reuse the assignment in the future without worrying about a "new" student getting a solution from the past. Although this seems logical, a colleague of mine scours the web for postings of his assignments. He developed a nice automated tool to do this for him. He says that he finds a significant portion (~40%) have been posted, often to sites like http://www.chegg.com Thus, if an assignment has ever been posted on the web, it will be there forever. Even if it is not on the web, a solution from a "friend" (who did the same assignment previously) may be available. My take is that cheaters will cheat.

I encourage students to look for help on the web. If they find help, I ask that they cite the link in their code. This way they can go back to what they found helpful without repeating the search that got them to this information. By citing a reference, you are declaring that your work is based on code you found elsewhere and are giving credit to the author. But, I also say that in using the code, you are taking responsibility for its correctness. You cannot say "It is not my fault the code I copied from the web doesn't work!".

Supply a reference implementation to the student

This can be done at different times, for different purposes.

  • Supply a reference implementation in "object" code (an executable). This may be done when the assignment is posted. The motivation of this approach is to give the student an "oracle" that they can test against. Here you are emphasizing "testing" in that the student must figure out various test cases and then compare the results of their code to that of the "oracle". This can also be viewed as a means of resolving ambiguities in the assignment. If two things in the specification may be in conflict, the student must make the same choice as the "oracle".

    This is fine for "compiled" languages, but does not work for scripting languages. If one is really paranoid about Java de-compilers, run the reference code through an obfuscater. The student may be able to "de-compile" it back to source, but the source won't look anything like code a human would write.

  • Supply a reference implementation in "object" code after the due date. Then allow students to gain back points by fixing their implementation. This emphasizes the requirement of a professional to get the job done correctly. If you hire someone to paint your house, and they only complete 75% of the job, they cannot expect to be paid with a "C" grade. You want the entire house painted, and will only pay at that time. When I was in engineering school (a long time ago, with small class sizes), our assignments were marked C&R (correct and return). The assignment was not complete until you had the correct answer and demonstrated how you got it.

  • Supply a reference implementation in "source" code after the due date. Here you are providing the student with a "master work" that the student may study and learn how you (the master) decomposed the specification and translated it to code. This forces the student to read code and create a mental model of how this implementation works. In industry, this is a normal part of most projects. You have to understand how the code (which you did not write) works before you can fix/extend it. You can become a much better programmer by studying other's code and understanding how they wrote the code.

    For small assignments, I often present my solution by projecting it onto the screen from my laptop and reviewing it in class. The students may use their cell phones and snap pictures as I discuss my solution. I only do this when the review will fit in a single lecture or less. I do not spend class time reviewing every assignment.

    For larger assignments, you may choose to provide the reference implementation via a link the students can download and do with as they please. If a "new" student submits this solution when you reuse the assignment, you may catch this by using MOSS to catch plagiarism. This is what I do for my larger assignments.

    There is one slight alternative to giving out the source directly. My colleague (mentioned above) wrote a program called "shadow" which turns a text document your source code into an HTML page. When you view the HTML page, you "see" the source and can read it to your hearts content. However, if you try and copy/paste it, you get a ton of obfuscating HTML code with the text "hidden" in it. Then only way to recover the original text is to type it in (or reverse engineer the obfuscation code). His theory is "If you can reverse engineer this obfuscation, you don't need to be taking this class". The two links in this paragraph show a HelloWorld.java in both forms.

My personal opinion is that the more code students read, the more proficient they will become. Thus, I tend to provide (or at least discuss) my solution to assignments with the students.

  • $\begingroup$ This is a gorgeous answer, and well-deliniated. I know I've said this before, but I really hope we get to hear more from you. $\endgroup$ – Ben I. Mar 23 '18 at 3:44
  • $\begingroup$ I always love to read things from the voice of experience. I second Ben I. in hoping to see more of your work here. $\endgroup$ – Gypsy Spellweaver Mar 23 '18 at 4:12

Reading an answer is not the same thing as solving a problem. I think different areas of the brain are engaged. Solving the problem yourself is a stronger reinforcement of the ideas certainly.

Frustration is a mind killer. Students shouldn't be frustrated when they are trying to learn and as novices they have few tools for problem solving.

So, to resolve the dilemma, yes, make answers available, but not in the same document and not at the same time. One way is to provide answers only when asked, and after some assurance that the student has spent some mental effort on the exercise. If an exercise is given on Monday, don't provide answers until Wednesday, for example, or some variation on that.

If the size of your student group isn't too large you could give out answers only one-to-one on personal request. You could examine the student solution ideas to dispel any misconceptions. If you get a lot of requests you may need to change your teaching a bit, so that the exercise becomes more natural.

Another option, and this one for when your student numbers are too large to engage individually, is to provide answers (after an interval) for only half of the exercises and assure that the ones that are not answered by you cover the same concepts as those you do answer.

A third option is to provide an additional exercise on the same topic with any answer for a given exercise. Give the student a way to exercise the grokking part of the brain, not just the reading part.

  • $\begingroup$ I don't know what the grokking part of the brain is, but maybe that's what I'm doing too?, see my answer below. $\endgroup$ – Java Jive Mar 17 '18 at 0:45

I think this answer is a little different, please remand me if not - I provide an algorithm with my coding assignments, and I almost always have code I can point to in their notes or previous assignments that is exactly what they need to fill in the algorithm. First I give a general description of the problem:

Create a Windows forms application named Squares with a text box, a button, and a label. When the user enters a number in the text box and presses the button, get the number, square it, and write the square to the label. Write a function to take the number and return the square. Be sure you handle invalid input.

If that's all they need to read, they can go from there. If they need to read further, then what follows in the same document is the step by step algorithm, but not code. If they get stuck in the algorithm, on, for example, a line that says:

Declare an integer variable to hold the value from the text box.

Then I point them to their notes for a myriad of examples for how to declare an integer variable, or even to a previous, simpler exercise where they had to do it. In other words, I make them find the answer themselves. This gives them a greater feeling of accomplishment and also makes them less dependent upon me.

I find that by giving them this "scaffolding", I rarely have to provide an actual code solution, but will upon request.


Let's see if I can answer the questions head on here.

Should I provide answers to the exercises?

Yes. programming is not like mathematics, although they are closely related. They are multiple ways to achieve the same results. Some students appreciate when they are provided with the expected answer.

If so should I include them as a part of the document with the exercises or as a separate document?

Separate document would be better. There are a lot of students who dont want to be treated with holding hands. They can easily ignore the separate document while those who need it can look at it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.