When teaching students (especially in code, but this can apply to any subject), how do you prevent near verbatim answers that match your examples?

For example, I tell students how to find a document by ID in an array of documents. I show them the code foundDocument = documentArray.find(singleDocument => singleDocument._id = id). I then ask students to find a fruit in fruitArray. The answer I'll get is foundDocument = fruitArray.find(singleDocument => singleDocument._id = id), which works, but not the ideal answer.

Some notes based on the content discussion and answers so far:

This is sort of for a project. I teach both one off weekend classes and long term coding mentorship and this comes up in both. The goal of the weekend class is to build a website by the end. The goal of the mentorship is for the singular student to have built an MVP of their product.

The array example above was the simplest and shortest example I could think of to demonstrate my issue. I also see this happen where whole files get copied and the students expects something different to happen.

What I'm hoping to prevent is the pattern matching that students sometimes do but they don't fully understand the why of what they are doing. I've also seen (and done this myself) often in the STEM fields. You find a formula that works and re apply it but not understand what you're doing.

  • 30
    What do you think the ideal answer is? If you gave me that example and that instruction I would produce exactly what you are bothered by getting. I would probably consider any other approach to be needless work.
    – Bryan Krause
    Commented Sep 10, 2018 at 20:11
  • Hmmm. I think you need a lesson on "intention revealing names". I hope you emphasize that and make them practice it. Otherwise, copy, paste, fixup, is always the student's preferred strategy. Some professionals too, sad to say.
    – Buffy
    Commented Sep 10, 2018 at 21:02
  • 29
    This sort of question works much better and will get more relevant answers if you post it instead at CSEducators: cseducators.stackexchange.com. That site is optimized for questions like this.
    – Buffy
    Commented Sep 10, 2018 at 21:04
  • 5
    @merlinpatt: Before you ask on Computer Science Educators, note that copy-pasting of questions is frowned upon here (oh, the irony), but it’s usually okay to re-ask a question if you want a different perspective from another community for some reason, emphasise on this, and reference the previous incarnation of your question. I will not migrate the question (as requested by flags) as I do not consider it off-topic and several answers are not CS-specific.
    – Wrzlprmft
    Commented Sep 11, 2018 at 5:53
  • 6
    I'm a programmer and I don't really understand what sort of answer you were expecting here. foundFruit = fruitArray.find(singleFruit => singleFruit._id = id)? x = fruitArray.find(y => y.z = z)? There's not really any room for variation other than changing variable names. (ignoring that that should be == in most languages) Commented Sep 11, 2018 at 10:36

6 Answers 6


When teaching students...how do you prevent near verbatim answers that match your examples?

I ask questions that cannot be answered correctly by near-verbatim matches of my examples.

  • 3
    While generally a good idea, this answer doesn't entirely work for software engineering. The example given in the question demonstrates using a lambda to locate an element in an array based on a specific property. There isn't really a way to make a verbatim copy of the example not work; the example shows the correct syntax, so it'll work, that's just how the programming language functions. Commented Sep 11, 2018 at 14:19
  • 10
    @anaximander: In that case you ask a different simple question that requires understanding how lambdas and find works. Software engineering is not special in this regard. Commented Sep 11, 2018 at 16:17
  • 6
    @anaximander I think in the given example it would help to at least use different properties (e.g. ask to find by name instead of id). Instead of such generic properties you could also use something more realistic (e.g. document.charCount, fruit.calories). Then you can make slightly more complex examples, like find all documents with more than X characters and ask for find all fruits with less than X calories in the hopes that at least some students notice that document.calories does not make much sense.
    – kapex
    Commented Sep 11, 2018 at 18:31

This answer is specific to the field of computer science, in keeping with the OP's question. Obviously the answer is much different if we were talking about a creative writing class or something.

In the field of computer science, there sometimes is a "best way" to do something. In your example, you are searching an array for a specified object. In most languages, array type objects have a find() function. This is the "best way" to access the array. I would actually consider it to be more wrong if a student used another approach to iterate over an array looking for a specific element.

I will touch on the nuance of using the identifier singleDocument in searching for a fruit in a fruit array. Perhaps this is what worries you? Yes, ideally a student should change singleDocument to something like singleFruit. Perhaps make a side comment to students in class about such practices, as it does indeed matter if we care about intelligible code. I would then leave it at that. Students who persist in using bad naming practices in their code usually end up getting themselves twisted up in longer projects and learn the folly of their ways.

I will add as an aside that when I first was learning to write computer code (Java), I sometimes made "mistakes" like the one you show (no identifier name change). This was due to the fact that I did not fully understand what could be changed in code and what could not be. I was more worried about finishing the project and less worried about writing really clean code. As I became more advanced, I quickly learned how to rectify issues such as changing identifier names to be more meaningful.

  • 5
    Students who persist in using bad naming practices in their code usually end up getting themselves twisted up in longer projects and learn the folly of their ways. - Is this true? I don't teach a lot of coding, so maybe I don't see it, but it has not been my experience that "students usually learn the folly of their ways."
    – Kimball
    Commented Sep 11, 2018 at 14:57
  • 2
    @Kimball This depends a lot on how far they go in the subject. In the case of CS, sure, you can have bad coding practices and finish the 150 line solutions in CS 101. But when you get to CS 201, 202, 203, etc. and have to produce projects of 1000+ lines and multiple classes, you either correct your ways or fail.
    – Vladhagen
    Commented Sep 11, 2018 at 15:11
  • 5
    Re "bad naming practices": The length of a variable name should be directly proportional to the amount of code that can interact with it. In this case, the parameter is used exactly once, right next to its definition. It should be neither singleDocument nor singleFruit, but rather something short like x. Then you wouldn't have this copy & paste problem in the first place, because there would be nothing to change.
    – Kevin
    Commented Sep 11, 2018 at 17:19
  • @Kimball - I'm not sure I agree with Vladhagen's comment that writing projects with longer chunks of code will break students of bad habits like inappropriate identifiers. In practice, most courses are short enough that if you can write your code int the first place, you may not be away from it long enough to forget what things mean, even with multiple courses. Maintaining code written a few months ago will do that. However, courses where you're programming as a team with other students can also do this, and is likely to happen in at least one course.
    – RDFozz
    Commented Sep 12, 2018 at 18:01
  • @RDFozz At least in the CS classes I took, the upper division courses had projects that were 1) much too long to get away with bad naming conventions and 2) usually collaborative. There is obviously no way to force good naming conventions, but I found that very, very, very few people made it to the upper division CS course and still had bad naming conventions.
    – Vladhagen
    Commented Sep 12, 2018 at 18:19

It looks like the problem is correctness output vs clarity of code? In which case, a consistently used markscheme that gives/docks points for correct output and further points for correct use of variable names and any other relevant conventions would motivate students to pay attention to such issues, in the same way that eg English teachers give/dock points for grammar and spelling, math teachers for showing working, physics teachers for drawing diagrams...

If they are not first year students, you could also motivate the practice by asking them to bring along some code from previous years and getting them to edit/extend it. Or providing examples with the same functionality but different readability for them to alter.


Why not do a multiple choice question “ which of the following will do x?” with one correct version and slight errors in the others - can even do partial marking depending on the error.

I have this in excel functions like vlookup with a list that asks which version will return the name or price etc


If you are marking the students answers/project/exercises (that contain code), one trick is to leave 5% to code quality.

This means clean comments, sensible variable names and no useless code. Its minor and unlikely to be the edge between fail and pass, but helps encourage good practice (and most of the times students realise that it is in fact easier for them to use good practices!)


When tutoring my fellow students it is of utmost important that they understand the basic concept behind what they are doing or else they will just come again and ask me the next week. As far as I have experienced learning only really takes place if they figure out the solution on their own instead of copy pasting. This will take a lot more effort and time at the beginning but the payoff is well worth it.

Depending on the age of your students you should point them to the documentation of a function/object and let them figure it out by themselves. If they want to program properly reading documentation is one of the most essential parts, if this is too hard (especially at the beginning) you can give them the method signature and an abstract explanation.

Arrays.find(item => item.property == needle)

haystack = ....
item = ....
needle = ...

In this case they have to at least replace the variable names with matching names and abstract the assignment part. If lambdas are required make sure that you have covered them in an earlier example and reference it, in this case you can even keep the example more general

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .