“Programming isn’t about what you know; it’s about what you can figure out.”
– Chris Pine
Now that that’s out of the way…
This is something that students struggle with in the classroom. I think that kids are often so fixated on getting to what’s the right answer they try and speed through the process to get there. Just go into a math class and listen to a teacher tell everyone they must show their work to get credit and you’ll see the same thing.
Like most teachers, I do my best to try and convince students that it’s okay to be wrong sometimes. It’s better to go through the right process, but still come up with the wrong answer, than it is to be so fixed on getting the right answer that you forget how you got there.
Not sure that I have a good solution though.
We spend a lot of time, especially early in the year, looking anonymously at each others’ code. During these code reviews I try and find at least one example of code that clearly doesn’t work, but shows that the student’s thought process was going the right direction. I’ve even shown some that just wrote in comments about what they wanted the code to do, even though they had no idea what the right code is. This seems to work fairly well.
I’m also a big fan of writing code on paper. When I grade these I try to find places to add points to a grade rather than looking for places to take off points.
But it’s pretty easy to spot the students that are no longer afraid of errors and exceptions. They just make some type of frustrated noise and then move on. Those that haven’t learned to embrace the process just put their heads down or stare out into space.